Set Selected Item of WPF Combobox to User Setting

三世轮回 提交于 2019-12-24 09:38:19

问题


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" SelectedValue="{Binding Source={x:Static my:MySettings.Default}, Path=DefaultCategory, Mode=TwoWay}"/>

回答1:


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}" ... />


来源:https://stackoverflow.com/questions/4946167/set-selected-item-of-wpf-combobox-to-user-setting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!