【问题标题】:wpf binding combobox selectedvaluepathwpf 绑定组合框 selectedvaluepath
【发布时间】:2012-04-06 06:25:23
【问题描述】:

我的视图模型中有一个类型字符串(selectedextensionvalue)的列表。如何将我的组合框的 selectedvaluepath(也是列表字符串类型)绑定到 selectedextensionvalue。我不知道语法。有人可以帮忙吗?

提前致谢, 舱底

【问题讨论】:

    标签: wpf binding combobox


    【解决方案1】:

    如果你有一个字符串集合,那么你就不需要使用SelectedValuePath 属性。您可以在字符串类型的ViewModel 中添加一些字符串字段。

    public string SelectedStringValue
    {
        get;
        set;
    }
    

    在 xaml 中:

    <ComboBox ItemsSource="{Binding Path=selectedextensionvalue}"
              SelectedItem="{Binding Path=SelectedStringValue, Mode=OneWayToSource}" />
    

    编辑:

    但是,如果您希望ComboBox 选择一些特殊项目(例如,您存储在数据库中的项目),那么属性SelectedStringValue 应该在setter 中引发PropertyChanged 通知,xaml 将如下:

    <ComboBox ItemsSource="{Binding Path=selectedextensionvalue}"
              SelectedItem="{Binding Path=SelectedStringValue, Mode=TwoWay}" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-06
      • 2012-06-18
      • 2011-03-09
      • 1970-01-01
      相关资源
      最近更新 更多