I try bind List to combobox, but combobox inside of DataTemplate in another control
<ScrollViewer Grid.Row="1" >
<ListBox Height="Auto" x:Name="ListOfElements" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}"/>
<ComboBox ItemsSource="{Binding Types}">
</ComboBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
And C# is
public partial class MainWindow : Window
{
public ObservableCollection<BoardElement> BE { get; set; }
public MainWindow()
{
InitializeComponent();
Initialize();
}
public void Initialize()
{
BoardElement b = new BoardElement("D1", 14);
BoardElement c = new BoardElement("D2", 14);
BoardElement e = new BoardElement("D3", 14);
BE.Add(b);
BE.Add(c);
BE.Add(e);
ListOfElements.ItemsSource = BE;
int a =ListOfElements.Items.Count;
}
}
Class of Board Element
public class BoardElement
{
public List<string> Types = new List<string> { "DIP 6", "DIP 8", "DIP 14", "DIP 16", "DIP 18", "DIP 20", "DIP 22", "DIP 24", "DIP 28", "DIP 32", "DIP 36", "DIP 40", "DIP 42", "DIP 48", "DIP 52", "DIP 64" };
public string Name { get; set; }
public BoardElement()
{
}
public BoardElement(string name, int type)
{
this.Type = type;
this.Name = name;
}
}
How i need to Bind to DataTemplate some List inside my class? Or i need to change my code? This string needs only for users when it's create new element and choosy type fo it.