Issue with TabControl which ContentTemplate contains a TabControl
In my WPF application, I have a TabControl named ParentTabControl, which
ContentTemplate is composed of several controls, including a TabControl
named ChildTabControl.
ParentTabControl contains, say, 2 tabs (each one bound to a different
source), where as ChildTabControl always contain 1 tab. I'm focusing the
first tab of ParentTabControl. By default, the first (the only one) tab of
ChildTabControl is selected. The problem is that, if I switch to the
second tab of ParentTabControl, the tab of its ChildTabControl is not
selected. Is that a normal behavior? How can I do to always select a tab?
I hope I'm clear enough. Here is some code:
ParentTabControl:
<TabControl Name="ParentTabControl"
ItemsSource="{Binding ParentItemsSource}"
ContentTemplate="{StaticResource ResourceKey=ContentTemplate}"
IsSynchronizedWithCurrentItem="True" />
ChildTabControl:
<DataTemplate x:Key="ContentTemplate">
<TabControl Name="ChildTabControl"
ItemsSource="{Binding ChildItemsSource,
Converter={StaticResource
ResourceKey=ItemToObservableCollectionConverter }}" />
</DataTemplate>
ItemsSource:
public ObservableCollection<ParentData> ParentItemsSource { get; set; }
public class ParentData
{
public ChildData ChildItemsSource { get; set; }
}
Converter:
public class ItemToObservableCollectionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
return new ObservableCollection<object> { value };
}
}
Thank you.
No comments:
Post a Comment