我目前正在構建一個簡單的GUI程序,我碰到了希望快速修復選項卡控件自定義的問題。我的選項卡當前處於活動狀態時設置爲「淺藍色天空」。我有兩個標籤框,其中一個我想更改爲Blue Violet。當我爲要改變的標籤區域輸入顏色代碼時,什麼都不會發生。XAML WPF:選項卡控件
代碼注意:我正在嘗試更改文件,選項和幫助選項卡。您將能夠在我的代碼中看到我試圖將背景設置爲「BlueViolet」。
讓我知道你是否需要一張照片。
這裏是我的代碼:
<!---Main Class-->
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="CartTools" Height="700" Width="1135" Name="Practice" FontSize="14" Opacity="1">
<Window.Resources>
<!---Tab items for Cart customization-->
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid>
<Border
Name="Border"
Background="LightBlue"
BorderBrush="Black"
BorderThickness="1,1,1,1"
CornerRadius="30,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="LightSkyBlue" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Border" Property="Background" Value="LightGray" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid Background="AliceBlue">
<!---File, Options, Help tabs-->
<TabControl HorizontalAlignment="Left" Name="TabControl1" Width="215" Margin="0,0,0,286">
<TabItem Header="File" Name="TabItem1" Background="BlueViolet">
<Grid>
<Label Height="28" Margin="6,6,79,0" Name="Label1" VerticalAlignment="Top">New</Label>
<Button Height="23" HorizontalAlignment="Left" Margin="6,40,0,0" Name="Button1" VerticalAlignment="Top" Width="75">Button</Button>
</Grid>
</TabItem>
<TabItem Header="Options" Name="TabItem2" Background="BlueViolet">
<Grid />
</TabItem>
<TabItem Header="Help" Name="TabItem3" Background="BlueViolet">
<Grid />
</TabItem>
</TabControl>
<!---Cart Management Tabs-->
<TabControl Margin="251,0,12,12" Name="TabControl2">
<TabItem Header="CartFunctions" Name="TabItem4">
<Grid>
<RadioButton Height="16" Margin="6,6,0,0" Name="RadioButton1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120">RadioButton</RadioButton>
<RadioButton Height="16" HorizontalAlignment="Left" Margin="6,28,0,0" Name="RadioButton2" VerticalAlignment="Top" Width="120">RadioButton</RadioButton>
<CheckBox Height="16" HorizontalAlignment="Left" Margin="6,50,0,0" Name="CheckBox1" VerticalAlignment="Top" Width="120">CheckBox</CheckBox>
</Grid>
</TabItem>
<TabItem Header="Cart Configuration" Name="TabItem5">
<Grid />
</TabItem>
<TabItem Header="Cart I/O" Name="TabItem6">
<Grid />
</TabItem>
<TabItem Header="CMS" Name="TabItem7">
<Grid />
</TabItem>
<TabItem Header="Blocking Database" Name="TabItem8">
<Grid></Grid>
</TabItem>
</TabControl>
</Grid>
</Window>
謝謝!
但是當你想看BlueViolet?如果TabItem.IsSelected爲True,則將Background設置爲LightSkyBlue,如果它爲False,則將Background設置爲LightGray。沒有機會拿出BlueViolet。 – LPL