C
C#5mo ago
estzwei

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
1 Reply
estzwei
estzweiOP5mo ago
Nvm I solved it by Databinding the Value of the KeyValuePair to the DataContext of the Stack panel
Want results from more Discord servers?
Add your server