简体   繁体   中英

Customized TabItem in ResourceDictionary

I have created a TabItem in a ResourceDictionary and use it in my UserControl but the defined content won't show up, why and how to fix this?

The ResourceDic:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
    <ControlTemplate x:Key="T1" TargetType="sdk:TabItem">
        <sdk:TabItem>
            <sdk:TabItem.Header>
                <StackPanel Orientation="Horizontal">
                    <sdk:Label Content="{TemplateBinding Header}"/>
                    <Button Content="X" Margin="15,0,0,0"/>
                </StackPanel>
            </sdk:TabItem.Header>

            <toolkit:DockPanel MinWidth="600">
                <Grid toolkit:DockPanel.Dock="Left">
                    <sdk:Label Grid.Row="2" Grid.Column="0" Content="Pic:"/>
                    ...
                </Grid>
            </toolkit:DockPanel>

        </sdk:TabItem>
    </ControlTemplate>
</ResourceDictionary>

The UserControl:

<UserControl x:Class="PortView" ....>
    <UserControl.Resources>
                <ResourceDictionary Source="PortfolioTemplateDictionary.xaml" />
    </UserControl.Resources>

    <Grid>
        <sdk:TabItem Template="{StaticResource T1}" Header="Page 2"/>
    </Grid  
    ...
</UserControl>

I have now used the approach explained in this article: TabItem in a separate XAML

<UserControl x:Class="WpfApplication19.Tab1Data"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         >
    <Grid>
        <TextBlock Text="Tab Data" />
    </Grid>
</UserControl>

<TabControl>
    <TabItem Header="Tab 1">
        <tabData:Tab1Data />
    </TabItem>
</TabControl>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM