문제

I have a control that contains following XAML code. It works fine excepted that I caInnot switch to another TabItem. I read that TabControl virtualizes the TabItem, I suspect the strange behaviour, namely that I cannot get to display any other TabItem as the first one, is related to this.

    <TabControl ItemsSource="{Binding Items}">
        <TabControl.ItemTemplate>
            <DataTemplate> <!-- header -->
                <TextBlock Text="{Binding Title}"></TextBlock>
            </DataTemplate>
        </TabControl.ItemTemplate>
        <TabControl.ContentTemplate>
            <DataTemplate x:Shared="False"> <!-- tabitem content -->
                <controls:ItemControl Item="{Binding}" />
            </DataTemplate>
        </TabControl.ContentTemplate>
    </TabControl>

I tried to set the x:Shared attribute of the DataTemplate to False but has not the expected effect. Is there a way to reach this without going the way of using a custom style and replacing the TabControl with an ItemsControl. I mean the functionality of TabControl is what I would like, I would like to simply use it with ItemsSource binding...

도움이 되었습니까?

해결책

This behaviour will happen if you are binding to a collection that has duplicate objects in it. Duplication can occur due to having added an object multiple times or because equality has been redefined for the objects in question.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top