You need to create a data source for the ComboBox. An instance of the following class is set as the ItemsSource (the insignificant fields are omitted):
public class TemperatureDimension : IDimension, IEnumerable { private List<IUnit> _Units; public List<IUnit> Units { get { return _Units; } } public TemperatureDimension() { _Units =new List<IUnit>{ new Celsius(), new Kelvin(), new Farenheit() }; } public IEnumerator GetEnumerator() { return _Units.GetEnumerator(); } }
In principle, it is logical that this code does not work and the ComboBox is not populated with data. I see the following solutions to this problem:
1) Write something like
<ComboBox Width="100" Height="30" ItemsSource="{Binding Dimension.Units}" />
2) Correct the code so that the class is a collection containing Items. I tried to solve this problem by implementing the IEnumerable interface, returning a list enumerator in the GetEnumerator method. But to no avail.
Any ideas?
UPD. I also tried to implement the IEnumerable <T> interface. In this case it is not compiled.
IEnumerable
, butIEnumerable<IUnit>
. What exactly is not compiled in this case? - VladD{Binding Dimension.Units}
? It seems everything is correct. What writes to the log (Output window) about Binding errors? - VladD