【发布时间】:2011-05-17 10:39:57
【问题描述】:
我有一堂课:
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。我需要类似的东西。
【问题讨论】:
标签: c# wpf xaml data-binding combobox