我有一个类:WPF数据绑定:如何使用XAML将数据绑定到组合框?
public class AccountDetail
{
public DetailScope Scope
{
get { return scope; }
set { scope = value; }
}
public string Value
{
get { return this.value; }
set { this.value = value; }
}
private DetailScope scope;
private string value;
public AccountDetail(DetailScope scope, string value)
{
this.scope = scope;
this.value = value;
}
}
和枚举:
public enum DetailScope
{
Private,
Business,
OtherDetail
}
最后,我有一个文件名为.xaml:
<Window x:Class="Gui.Wpf.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test"
SizeToContent="WidthAndHeight">
<Grid>
<ComboBox
Name="ScopeComboBox"
Width="120"
Height="23"
Margin="12" />
</Grid>
</Window>
我希望做两件事情:
- 我希望数据绑定
DetailsScope
枚举值组合框值。我不希望 直接绑定枚举值,因为最后一个枚举值将是OtherDetail
而不是Other detail
(添加了空格字符和小写字母'd')。 - 我希望数据绑定组合框中的选定值到
AccountDetail
对象的 实例中指定的值。
你能帮我吗?谢谢。
更新:我发现此帖子http://blogs.msdn.com/b/wpfsdk/archive/2007/02/22/displaying-enum-values-using-data-binding.aspx。我需要类似的东西。
尼古拉斯,感谢您的答复。我正在寻找更多面向XAML的解决方案,例如:http://blogs.msdn.com/b/wpfsdk/archive/2007/02/22/displaying-enum-values-using-data-binding.aspx – Boris 2010-11-29 18:49:55