1212using System . Threading . Tasks ;
1313using System . Windows ;
1414using System . Windows . Controls ;
15+ using System . Windows . Data ;
1516
1617namespace OnnxStack . UI . UserControls
1718{
@@ -22,6 +23,7 @@ public partial class ModelPickerControl : UserControl, INotifyPropertyChanged
2223 {
2324 private readonly ILogger < ModelPickerControl > _logger ;
2425 private readonly IStableDiffusionService _stableDiffusionService ;
26+ private ICollectionView _modelCollectionView ;
2527
2628 /// <summary>Initializes a new instance of the <see cref="ModelPickerControl" /> class.</summary>
2729 public ModelPickerControl ( )
@@ -46,8 +48,11 @@ public OnnxStackUIConfig UISettings
4648 set { SetValue ( UISettingsProperty , value ) ; }
4749 }
4850 public static readonly DependencyProperty UISettingsProperty =
49- DependencyProperty . Register ( "UISettings" , typeof ( OnnxStackUIConfig ) , typeof ( ModelPickerControl ) ) ;
50-
51+ DependencyProperty . Register ( "UISettings" , typeof ( OnnxStackUIConfig ) , typeof ( ModelPickerControl ) , new PropertyMetadata ( ( d , e ) =>
52+ {
53+ if ( d is ModelPickerControl control && e . NewValue is OnnxStackUIConfig settings )
54+ control . InitializeModels ( ) ;
55+ } ) ) ;
5156
5257 /// <summary>
5358 /// Gets or sets the supported diffusers.
@@ -58,8 +63,11 @@ public List<DiffuserType> SupportedDiffusers
5863 set { SetValue ( SupportedDiffusersProperty , value ) ; }
5964 }
6065 public static readonly DependencyProperty SupportedDiffusersProperty =
61- DependencyProperty . Register ( "SupportedDiffusers" , typeof ( List < DiffuserType > ) , typeof ( ModelPickerControl ) ) ;
62-
66+ DependencyProperty . Register ( "SupportedDiffusers" , typeof ( List < DiffuserType > ) , typeof ( ModelPickerControl ) , new PropertyMetadata ( ( d , e ) =>
67+ {
68+ if ( d is ModelPickerControl control && e . NewValue is List < DiffuserType > diffusers )
69+ control . ModelCollectionView ? . Refresh ( ) ;
70+ } ) ) ;
6371
6472 /// <summary>
6573 /// Gets or sets the selected model.
@@ -73,6 +81,25 @@ public StableDiffusionModelSetViewModel SelectedModel
7381 DependencyProperty . Register ( "SelectedModel" , typeof ( StableDiffusionModelSetViewModel ) , typeof ( ModelPickerControl ) ) ;
7482
7583
84+ public ICollectionView ModelCollectionView
85+ {
86+ get { return _modelCollectionView ; }
87+ set { _modelCollectionView = value ; NotifyPropertyChanged ( ) ; }
88+ }
89+
90+
91+ private void InitializeModels ( )
92+ {
93+ ModelCollectionView = new ListCollectionView ( UISettings . StableDiffusionModelSets ) ;
94+ ModelCollectionView . Filter = ( obj ) =>
95+ {
96+ if ( obj is not StableDiffusionModelSetViewModel viewModel )
97+ return false ;
98+
99+ return viewModel . ModelSet . Diffusers . Intersect ( SupportedDiffusers ) . Any ( ) ;
100+ } ;
101+ }
102+
76103
77104 /// <summary>
78105 /// Loads the model.
0 commit comments