开发者

Set Selected Item of WPF Combobox to User Setting

开发者 https://www.devze.com 2023-02-09 06:17 出处:网络
I have a combo box with an item source set as a collection of \'Category\'.The SelectedValuePath is the CategoryID property.I have a user setting \'DefaultCategory\' that is an integer of which should

I have a combo box with an item source set as a collection of 'Category'. The SelectedValuePath is the CategoryID property. I have a user setting 'DefaultCategory' that is an integer of which should set the CategoryID. I want the combo box to have a selection of the DefaultCategory user setting.

xmlns:my="clr-namespace:MyApp"

<ComboBox x:Name="cmbCategory" DisplayMemberPath="Category" SelectedValuePath="CategoryID" Sel开发者_开发问答ectedValue="{Binding Source={x:Static my:MySettings.Default}, Path=DefaultCategory, Mode=TwoWay}"/>


You could create an additional application setting called DefaultCategory_Selected of type int and scope of User, and then binding the SelectedIndex property to the setting.

<ComboBox SelectedIndex="{Binding Path=DefaultCategory_Selected, Mode=TwoWay}" ... />
0

精彩评论

暂无评论...
验证码 换一张
取 消