【问题标题】:Set Selected Item of WPF Combobox to User Setting将 WPF 组合框的选定项设置为用户设置
【发布时间】:2011-06-24 04:31:00
【问题描述】:

我有一个组合框,其中项目源设置为“类别”的集合。 SelectedValuePath 是 CategoryID 属性。我有一个用户设置“DefaultCategory”,它是一个整数,应该设置 CategoryID。我希望组合框可以选择 DefaultCategory 用户设置。

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

【问题讨论】:

    标签: wpf combobox selecteditem selectedvalue


    【解决方案1】:

    您可以创建一个名为 DefaultCategory_Selected 的附加应用程序设置,类型为 int,范围为 User,然后绑定 SelectedIndex 设置属性。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-04
      相关资源
      最近更新 更多