Let's say that I have the following class hierarchy:
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
public string DataName;
public ushort DataId;
public Constants.MyEnum DataEnum;
#endregion
}
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;
}
I would like to bind a DataContainer DataContainer ContainedData to a ListView and create an ItemTemplate containing:
My goals:
- I want Combobox to be able to display all possible MyEnum values
- I want Combobox to implement TwoWay binding to DataEnum field
Questions:
- How to achieve these goals?
- Data properties are of different types. Does it matter for a TextBox? If so, should they only be shown as strings? How to check the data? (i.e. make sure the user does not pass "abc" to the DataId field, etc.).
source
share