来自另一个程序集的Host TabItem

时间:2012-06-03 10:49:53

标签: c# wpf tabs

我正在尝试创建一个基本上包含Tab项的用户控件。如下所示,并尝试将其添加到另一个库中的选项卡控件。

//Grid.xaml in a.dll

<UserControl x:Name="Grid" x:Class="SomeClass"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <TabItem Header="Grid">
        <DataGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
    </TabItem>

</UserControl>

//TabView.xaml in b.dll
<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Views="clr-namespace:SomeClass;assembly=SomeAssembly" x:Class="SomeClass" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <TabControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >

        <Views:GridView/>

        <TabItem Header="This" />
        <TabItem Header="That" />


    </TabControl>
</UserControl>

我的问题是,它实际上在那里创建了标签,但没有显示标签的标题。我想知道我是否做得对,如何显示标题?

1 个答案:

答案 0 :(得分:0)

您的问题是您在a.dll中的控件不是TabItem。这是UserControl。您可以从TabItem继承它(这对WPF来说是一种坏方法)或使用组合:

//Grid.xaml in a.dll
<UserControl x:Name="Grid" x:Class="SomeClass"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <DataGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>

</UserControl>


//TabView.xaml in b.dll
<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Views="clr-namespace:SomeClass;assembly=SomeAssembly" x:Class="SomeClass" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <TabControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >

        <TabItem Header="Grid">
            <Views:GridView/>
        </TabItem>

        <TabItem Header="This" />
        <TabItem Header="That" />


    </TabControl>
</UserControl>