我显然在这里遗漏了一些东西。我正在尝试在 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 以确保我不会错过它。
谁能看到它不显示的原因?