I have searched for a solution for a day and a half. Most examples that I get that explain / semi explain the situation relate to a combobox with "static" type items. I have the following structure.
DataModel Item
ObservableCollection CombinedData inside DataFilter class (i.e has other properties including "ParentName used for buttoncontent")
ObservableCollection Filters inside DataFilterGroup class
DataFilterGroup is 1 item in DataViewModel
So window's DataContext is DataViewModel.
I have a DataTemplate in which I would like to show the DataFilterGroup items from code behind
This is where I need help with please!!
so basically: ItemsControl's Itemsource is bound to DataFilterGroup
How do I bind a combobox in the DataFilter so that it's items source point to DataFilter. Therefore the source will change (or the content of the combobox will change with every DataFilterGroup Item).
I apologise if this is a repeat question. What I have up to now is the following (and have tried several ways to bind the combobox but no items appear. Supprisingly enough the Buttoncontent show up. Special combo is control deriverd from Combobox which is a button and combobox.
private static DataTemplate DataFilterTemplate
{
get
{
DataTemplate DFT = new DataTemplate();
DFT.DataType = typeof(DataFilters);
FrameworkElementFactory Stack = new FrameworkElementFactory(typeof(VirtualizingStackPanel));
Stack.SetValue(VirtualizingStackPanel.DataContextProperty, new Binding());
Stack.SetValue(VirtualizingStackPanel.OrientationProperty, Orientation.Horizontal);
FrameworkElementFactory Item = new FrameworkElementFactory(typeof(SpecialCombo));
//Item.SetValue(SpecialCombo.DataContextProperty, new Binding());
Item.SetValue(SpecialCombo.ButtonContentProperty, new Binding("ParentName"));
Binding b = new Binding("CombinedData");
//b.RelativeSource.AncestorType = typeof(ItemsControl);
Item.SetBinding(SpecialCombo.ItemsSourceProperty, b);
//Item.SetValue(SpecialCombo.ItemsSourceProperty, new Binding("CombinedData"));
Item.SetValue(SpecialCombo.DisplayMemberPathProperty, "FullName");
Item.SetValue(SpecialCombo.SelectedValuePathProperty, "Index");
Item.SetValue(SpecialCombo.SelectedValueProperty, "SelectedItem");
Item.SetValue(SpecialCombo.ToggleVisibleProperty, new Binding("ComboVisibility"));
//Item.SetValue(SpecialCombo.SelectedValueProperty, new Binding("SelectedItem"));
Stack.AppendChild(Item);
DFT.VisualTree = Item;
return DFT;
}
}
Child is ItemsControl
Child.ItemsSource = DVM.Filters.FullCollection;
Child.ItemTemplate = DataFilterTemplate;