3
比方說,我有下面的類層次結構:WPF的ListView的ItemTemplate質疑
public static class Constants
{
public enum MyEnum
{
Value1 =0,
Value2,
Value3
}
}
public class Data : INotifyPropertyChanged
{
public Data(string name, ushort id, Constants.MyEnum e)
{
DataName = name;
DataId = id;
DataEnum = e;
}
#region Properties
// get/set implementation not shown
public string DataName;
public ushort DataId;
public Constants.MyEnum DataEnum;
#endregion
// INotifyPropertyChanged implementation not shown
// Fields implementation not shown
}
public class DataContainer
{
public DataContainer()
{
ContainedData = new ObservableCollection<Data>();
ContainedData.Add(new Data("data1", 1, Constants.MyEnum.Value1));
ContainedData.Add(new Data("data2", 2, Constants.MyEnum.Value2));
ContainedData.Add(new Data("data3", 3, Constants.MyEnum.Value3));
}
public ObservableCollection<Data> ContainedData;
}
我想數據綁定DataContainer的ContainedData到ListView並創建包含一個ItemTemplate:
我的目標:
- 我想組合框,以便能夠顯示所有可能MyEnum值
- 我想組合框來實現雙向綁定到DataEnum場
問題:
- 如何實現列出的目標?
- 數據的屬性具有不同的類型。這對TextBox來說很重要嗎?如果是這樣,我應該只將它們暴露爲字符串嗎?我如何驗證數據? (即確保用戶未在DataId字段中傳遞「abc」等)
這正是我一直在尋找的。謝謝! – Maciek 2009-12-04 21:29:25