2016-05-19 9 views
0

ここに私はすでに回答があるという質問があります。私は他人を助けるためにここにマークしたい。私は自分自身で定義されたタブコントロールを持っています。私が自動化を行うと、tabitemのコントロールツリーには検査が行われません。ここで enter image description here コードは次のとおりです。WPFユーザーコントロールが検査で表示されない

<Window.Resources> 
     <Style x:Key="TabControlStyle1" TargetType="{x:Type TabControl}"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type TabControl}"> 
         <Grid x:Name="templateRoot" ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local"> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition x:Name="ColumnDefinition0"/> 
           <ColumnDefinition x:Name="ColumnDefinition1" Width="0"/> 
          </Grid.ColumnDefinitions> 
          <Grid.RowDefinitions> 
           <RowDefinition x:Name="RowDefinition0" Height="Auto"/> 
           <RowDefinition x:Name="RowDefinition1" Height="*"/> 
          </Grid.RowDefinitions> 
          <TabPanel x:Name="headerPanel" Background="Transparent" Grid.Column="0" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"/> 
          <Border x:Name="contentPanel" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="1" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local"> 
           <ContentPresenter ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
          </Border> 
         </Grid> 

        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </Window.Resources> 
    <Grid> 
     <TabControl Margin="5" Style="{DynamicResource TabControlStyle1}"> 
      <TabItem Header="tab 1"> 
       <Button Width="90" Height="90" Content="btn1"/> 
      </TabItem> 
      <TabItem Header="tab 2"> 
       <Button Width="90" Height="90" Content="btn2"/> 
      </TabItem> 
     </TabControl> 
    </Grid> 

のTabItemが検査で見えないのはなぜ?

答えて

2

x:NameにContentPresenterを追加する必要があります。 ×:名前はPART_SelectedContentHost

<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 

enter image description here

でなければなりません
関連する問題