I am trying to bind a combobox with the Tabitems using converter
My converter class is as follows
public class TabItemsCollection : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
ItemCollection collection = value as ItemCollection;
IList names = new List();
foreach (TabItem ti in collection.SourceCollection)
{
names.Add(ti.Header.ToString());
}
return names;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
My xaml is as follows
//combobox
<ComboBox Name="cmbModule"
ItemsSource="{Binding ElementName=mnuMain, Path=Items, Converter={StaticResource MenuItemsConverter}}" SelectedIndex="{Binding ElementName=mnuMain, Path=SelectedIndex}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
//TabControl
<local:MenuTab Name="mnuMain"></local:MenuTab>
I am binding 'mnuMain' with items which is a custom tabcontrol in codebehind, as i am doing so i am unable to popularate combobox with tabitems becoz converter fires first and then the 'mnuMain'. If I create the Tabitems in xaml the combobox is popularated with tabitems.. but my problem is with dynamic binding. can some one suggest me where i am doing wrong