Guest User

Untitled

a guest
Jul 18th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <DataTemplate x:Key="ListComboboxTemplate">
  2. <ComboBox Margin="0,0,0,0" MinWidth="230" Height="22" ItemsSource="{Binding Path=DataContext.ListBoxContent, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
  3. ... >
  4.  
  5. public class ListItem
  6. {
  7. public IEnumerable<string> ComboBoxItems { get; set; }
  8. }
  9.  
  10. public class ViewModel
  11. {
  12. public ObservableCollection<ListItem> ListItems { get; }
  13. = new ObservableCollection<ListItem>();
  14. }
  15.  
  16. <ItemsControl ItemsSource="{Binding ListItems}">
  17. <ItemsControl.ItemTemplate>
  18. <DataTemplate>
  19. <ComboBox ItemsSource="{Binding ComboBoxItems}"/>
  20. </DataTemplate>
  21. </ItemsControl.ItemTemplate>
  22. </ItemsControl>
  23.  
  24. public MainWindow()
  25. {
  26. InitializeComponent();
  27.  
  28. var vm = new ViewModel();
  29. vm.ListItems.Add(new ListItem { ComboBoxItems = new string[] { "1.1", "1.2" } });
  30. vm.ListItems.Add(new ListItem { ComboBoxItems = new string[] { "2.1", "2.2" } });
  31.  
  32. DataContext = vm;
  33. }
Add Comment
Please, Sign In to add comment