2012-04-06 180 views
0

我有我的viewmodel中的类型字符串(selectedextensionvalue)列表。我怎样才能将我的组合框的selectedvaluepath(也是类型列表字符串)绑定到selectedextensionvalue。我不知道语法。有人可以帮忙吗?wpf绑定组合框selectedvaluepath

由于提前, 舱底

回答

0

如果你有一个字符串的集合,所以你不需要使用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}" />