我有两个属性,一个是字符串列表,另一个只是一个字符串。
private List<String> _property;
public List<String> Property
get
{
return new List<string>(){"string1", "string2"};
}
set{_property = value
}
public String SimpleStringProperty{get;set;}
我还有一个在 XAML 中定义的 Combobox
<Combobox ItemsSource="{Binding Property , Mode="TwoWay"}" Text="Select Option" />
现在组合框正确显示两个选项:“string1”和“string2”
当用户选择一个或另一个时,我想设置 SimpleStringProperty
具有该值。但是,通过双向绑定(bind)从组合框返回的“值”不是 selectedItem,而是 List<String>
。 .我该怎么做呢?我是 wpf 的新手,所以请原谅我的业余行为。
最佳答案
<Combobox ItemsSource="{Binding Property}" SelectedItem="{Binding SimpleStringProperty, Mode=TwoWay}" Text="Select Option" />
那是未经测试的,但它至少应该非常接近您的需要。
关于c# - WPF 组合框与 List<string> 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21898022/