2012-06-03 30 views
0

我想創建一個用戶控件,它基本上包括一個選項卡項。如下所示,並嘗試將其添加到另一個庫中的我的選項卡控件中。從另一個組件的主機TabItem

//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> 

我的問題是,它實際上創建了標籤,但沒有顯示標籤的標題。我想知道我是否正確地做了,我該如何顯示標題?

回答

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> 
相關問題