@@ -18,6 +18,9 @@ public partial class DevicePickerControl : UserControl, INotifyPropertyChanged
1818 private readonly IDeviceService _deviceService ;
1919 private DeviceInfo _selectedDevice ;
2020
21+ /// <summary>
22+ /// Initializes a new instance of the <see cref="DevicePickerControl"/> class.
23+ /// </summary>
2124 public DevicePickerControl ( )
2225 {
2326 if ( ! DesignerProperties . GetIsInDesignMode ( this ) )
@@ -27,26 +30,30 @@ public DevicePickerControl()
2730 }
2831
2932 public static readonly DependencyProperty UISettingsProperty =
30- DependencyProperty . Register ( "UISettings" , typeof ( OnnxStackUIConfig ) , typeof ( DevicePickerControl ) , new PropertyMetadata ( ( c , e ) =>
31- {
32- if ( c is DevicePickerControl control )
33- control . OnSettingsChanged ( ) ;
34- } ) ) ;
33+ DependencyProperty . Register ( "UISettings" , typeof ( OnnxStackUIConfig ) , typeof ( DevicePickerControl ) , new PropertyMetadata ( ( c , e ) =>
34+ {
35+ if ( c is DevicePickerControl control )
36+ control . OnSettingsChanged ( ) ;
37+ } ) ) ;
3538
3639 public static readonly DependencyProperty ExecutionProviderProperty =
37- DependencyProperty . Register ( "ExecutionProvider" , typeof ( ExecutionProvider ) , typeof ( DevicePickerControl ) , new PropertyMetadata ( ( c , e ) =>
40+ DependencyProperty . Register ( "ExecutionProvider" , typeof ( ExecutionProvider ? ) , typeof ( DevicePickerControl ) , new PropertyMetadata ( ( c , e ) =>
3841 {
3942 if ( c is DevicePickerControl control )
4043 control . OnSettingsChanged ( ) ;
4144 } ) ) ;
4245
4346 public static readonly DependencyProperty DeviceIdProperty =
44- DependencyProperty . Register ( "DeviceId" , typeof ( int ) , typeof ( DevicePickerControl ) , new PropertyMetadata ( ( c , e ) =>
47+ DependencyProperty . Register ( "DeviceId" , typeof ( int ? ) , typeof ( DevicePickerControl ) , new PropertyMetadata ( ( c , e ) =>
4548 {
4649 if ( c is DevicePickerControl control )
4750 control . OnSettingsChanged ( ) ;
4851 } ) ) ;
4952
53+
54+ /// <summary>
55+ /// Gets or sets the UI settings.
56+ /// </summary>
5057 public OnnxStackUIConfig UISettings
5158 {
5259 get { return ( OnnxStackUIConfig ) GetValue ( UISettingsProperty ) ; }
@@ -56,45 +63,60 @@ public OnnxStackUIConfig UISettings
5663 /// <summary>
5764 /// Gets or sets the ExecutionProvider.
5865 /// </summary>
59- public ExecutionProvider ExecutionProvider
66+ public ExecutionProvider ? ExecutionProvider
6067 {
61- get { return ( ExecutionProvider ) GetValue ( ExecutionProviderProperty ) ; }
68+ get { return ( ExecutionProvider ? ) GetValue ( ExecutionProviderProperty ) ; }
6269 set { SetValue ( ExecutionProviderProperty , value ) ; }
6370 }
6471
6572 /// <summary>
6673 /// Gets or sets the DeviceId.
6774 /// </summary>
68- public int DeviceId
75+ public int ? DeviceId
6976 {
70- get { return ( int ) GetValue ( DeviceIdProperty ) ; }
77+ get { return ( int ? ) GetValue ( DeviceIdProperty ) ; }
7178 set { SetValue ( DeviceIdProperty , value ) ; }
7279 }
7380
74-
81+ /// <summary>
82+ /// Gets the devices.
83+ /// </summary>
7584 public IReadOnlyList < DeviceInfo > Devices => _deviceService . Devices ;
7685
7786
78-
87+ /// <summary>
88+ /// Gets or sets the selected device.
89+ /// </summary>
7990 public DeviceInfo SelectedDevice
8091 {
8192 get { return _selectedDevice ; }
8293 set { _selectedDevice = value ; OnSelectedDeviceChanged ( ) ; }
8394 }
8495
96+
97+ /// <summary>
98+ /// Called when UISettings changed.
99+ /// </summary>
85100 private void OnSettingsChanged ( )
86101 {
87- SelectedDevice = ExecutionProvider == ExecutionProvider . Cpu
102+ SelectedDevice = ExecutionProvider == Core . Config . ExecutionProvider . Cpu
88103 ? Devices . FirstOrDefault ( )
89- : Devices . FirstOrDefault ( x => x . DeviceId == DeviceId ) ;
104+ : Devices . FirstOrDefault ( x => x . Name != "CPU" && x . DeviceId == DeviceId ) ;
90105 }
91106
107+
108+ /// <summary>
109+ /// Called when SelectedDevice changed.
110+ /// </summary>
92111 private void OnSelectedDeviceChanged ( )
93112 {
113+ if ( _selectedDevice is null )
114+ return ;
115+
94116 if ( _selectedDevice . Name == "CPU" )
95117 {
96118 DeviceId = 0 ;
97- ExecutionProvider = ExecutionProvider . Cpu ;
119+ ExecutionProvider = Core . Config . ExecutionProvider . Cpu ;
98120 }
99121 else
100122 {
@@ -114,6 +136,4 @@ public void NotifyPropertyChanged([CallerMemberName] string property = "")
114136 }
115137 #endregion
116138 }
117-
118-
119139}
0 commit comments