1

私は明らかにここで何かが欠けています。WPFウィンドウのタブコントロールでテキストブロックを取得しようとしています。インターネットからいくつかのサンプルコードを取得し、それを少し変更しましたが、テキストブロックが表示されなくなりました。

編集 このスタイリングは責任があるようです

    <Window.Resources>
<Style TargetType="{x:Type TabItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabItem}">
                <Grid>
                    <Border 
         Name="Border"
         Background="{DynamicResource TabSelected}"
         BorderBrush="Black" 
         BorderThickness="1,1,1,1" 
         CornerRadius="6,6,0,0" >
                        <ContentPresenter x:Name="ContentSite"
           VerticalAlignment="Center"
           HorizontalAlignment="Center"
           ContentSource="Header"
           Margin="12,2,12,2"/>
                    </Border>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="Border" Property="Background" Value="{DynamicResource TabSelected}" />
                    </Trigger>
                    <Trigger Property="IsSelected" Value="False">
                            <Setter TargetName="Border" Property="Background" Value="{DynamicResource TabNormal}" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style  TargetType="{x:Type TabControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabControl}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <TabPanel 
         Grid.Row="0"
         Panel.ZIndex="1" 
         Margin="0,0,4,-1" 
         IsItemsHost="True"
         Background="Transparent" />
                        <Border 
         Grid.Row="1"
         BorderBrush="Black" 
         BorderThickness="1" 
         CornerRadius="0, 12, 12, 12" >

                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

編集終了

    <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="25"></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition Height="25"></RowDefinition>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition></ColumnDefinition>
    </Grid.ColumnDefinitions> 

    <Button Content="Button" Height="23" Grid.Row="0"  HorizontalAlignment="Left" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
    <TextBox Height="27" HorizontalAlignment="Left" Grid.Row="2" Name="txtMessages" VerticalAlignment="Top" Width="200" />
    <TabControl Grid.Row="1" Grid.Column="0" Height="258" HorizontalAlignment="Left" Margin="12,15,0,0" Name="tabMainContent" VerticalAlignment="Top" Width="351">
        <TabItem Header="Assigned Printers" Name="tabInstalledPrinters" Margin="0">
            <TabItem.Content>
                <StackPanel>
                    <Grid>
                        <Grid.RowDefinitions >
                            <RowDefinition></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0" Name="txtDisplayText" Height="23" Width="209" Text="Im Here" Background="Aqua" Margin="20,40,30,50" />
                    </Grid>
                </StackPanel>
            </TabItem.Content>
        </TabItem>
        <TabItem Header="Options" Name="tabOptions">
            <Grid />
        </TabItem>
    </TabControl>
</Grid>

すべてが期待どおりですが、Textblockが表示されないため、見逃さないようにAquaにしました。

誰もがそれが表示されない理由を見ることができますか?

4

1 に答える 1

3

スタイルContentPresenterからを削除しました。TabControl中に入れてくださいBorder

<Style TargetType="{x:Type TabControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabControl}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TabPanel Grid.Row="0" Panel.ZIndex="1" Margin="0,0,4,-1" IsItemsHost="True" Background="Transparent" />
                    <Border Grid.Row="1" BorderBrush="Black" BorderThickness="1" CornerRadius="0, 12, 12, 12" >
                        <ContentPresenter ContentSource="SelectedContent"/>
                    </Border>
                 </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
于 2012-10-15T17:19:27.647 に答える