2012-02-22 3 views
2

TabControl을 가지고 있고 그 안에 ContentControl이있는 TabItem이 있습니다. 이 ContentControl은 데이터 템플릿에 적용됩니다. 코드는 여기에 있습니다 :DataTemplate의 RelativeSource는 TabControl과 함께 작동하지만 TabItem과 함께 작동하지 않습니다.

<TabControl x:Name="tabControl1" Tag="Giving URI here works"> 
         <TabItem x:Name="tabItem1" Tag="Giving URI here doesnt work"> 
          <ContentControl ContentTemplate="{StaticResource myOptionsDataTemplate}"> 
           <StackPanel> 
            <TextBlock Text="Some Text" /> 
           </StackPanel> 
          </ContentControl> 
         </TabItem> 
</TabControl> 

그리고 데이터 템플릿은 다음과 같습니다

<DataTemplate x:Key="myOptionsDataTemplate"> 
     <Border> 
      <Grid> 
       <Grid.RowDefinitions> 
        <RowDefinition Height="Auto" /> 
        <RowDefinition Height="Auto" /> 
       </Grid.RowDefinitions> 
       <DockPanel LastChildFill="True"> 
        <Image Source="{Binding Path=Tag, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TabItem}}}" 
          Width="32" Height="32" 
          HorizontalAlignment="Left" 
          VerticalAlignment="Top" 
          DockPanel.Dock="Left" 
          Margin="0,0,4,0"/> 
        <Label Content="Some Text" 
          /> 
       </DockPanel> 
       <ContentControl Grid.Row="2" Content="{TemplateBinding ContentControl.Content}"/> 
      </Grid> 
     </Border> 
    </DataTemplate> 

공지 사항 DataTemplate을의 이미지 소스가 TabItem의의 태그입니다. 이것은 작동하지 않습니다. 하지만 TabControl의 태그를 사용하도록 소스를 변경하면 작동합니다.

TagItem의 Tag를 사용하는 것이 효과가없는 이유는 무엇입니까 ??

답변

3

Snoop과 같은 것을 사용하여 실제 비주얼 트리를 그릴 경우 TabControl의 머리글과 내용이 별도 영역에 있고 TabItems가 내용 영역이 아닌 머리글 영역에만있는 것을 볼 수 있습니다. 내용 영역에는 현재 SelectedItem 만 있습니다.

enter image description here

+0

감사합니다. Rachel. 그게 내가 놓친 분명한 사실 이었어. 이제 TabControl의 이상한 동작을 더 잘 이해합니다. – digitguy

관련 문제