WPF TabControl-设置TabItems的样式
程序员文章站
2022-06-09 19:12:57
<Window x:Class="WpfTutorialSamples.Misc_controls.StyledTabItemsSample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="StyledTabItemsSample" Height="150" Width="250"> <Grid> <TabControl Margin="10" BorderThickness="0" Background="LightGray"> <TabControl.Resources> <Style TargetType="TabItem"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="TabItem"> <Grid Name="Panel"> <ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="10,2"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter TargetName="Panel" Property="Background" Value="LightSkyBlue" /> </Trigger> <Trigger Property="IsSelected" Value="False"> <Setter TargetName="Panel" Property="Background" Value="White" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </TabControl.Resources> <TabItem Header="General"> <Label Content="Content goes here..." /> </TabItem> <TabItem Header="Security" /> <TabItem Header="Details" /> </TabControl> </Grid> </Window>效果如下:
转载 WPF Tutorial
上一篇: js 气泡排序