© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
1 reply
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Custom control Binding
C#CC# / help
3y ago
❔ Data binding
C#CC# / help
3y ago
Remove Tab Control
C#CC# / help
2y ago