estzwei
estzwei
CC#
Created by estzwei on 7/24/2024 in #help
Tab Control Data Binding
I have a tab control as follows and the ItemSource is Binded to a Dictionary.
<TabControl ItemsSource="{Binding Dict}" SelectedValuePath="Key" SelectedValue="{Binding SelectedValue}" >
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Key}" />
<Button Content="X" Command="{Binding CloseTabCommand}" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<StackPanel>
<Label Content="{Binding Value}"/>
</StackPanel>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
<TabControl ItemsSource="{Binding Dict}" SelectedValuePath="Key" SelectedValue="{Binding SelectedValue}" >
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Key}" />
<Button Content="X" Command="{Binding CloseTabCommand}" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<StackPanel>
<Label Content="{Binding Value}"/>
</StackPanel>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
How do I get the tab control to pass the value of the Dictionary to the ItemTemplate and ContentTemplate instead of a KeyValuePair? Also another similar question that I have is that, is it possible to databind the Value or Key of a KeyValuePair to a datatemplate for example, and the child elements of that DataTemplate would be able to reference the properties the of Value instead of Value.PropertyName
2 replies