更改TabItems的默认颜色(MahAppsMetro)

时间:2016-09-30 10:43:53

标签: wpf vb.net mahapps.metro

我正在使用MahAppsMetro并拥有TabControl - 实际上,非活动标签应该具有灰色前景并且在MouseOver上变为黑色。不知怎的,他们一直都是黑人.. 这就是我使用TabControl的方式:

<Controls:MetroWindow x:Name="MW_Window" x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Title="Example" Icon="/Example;component/pics/Example.ico" WindowStyle="ThreeDBorderWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="665.5" Width="759" ResizeMode="CanMinimize" NonActiveWindowTitleBrush="{DynamicResource AccentColorBrush}" NonActiveGlowBrush="{DynamicResource AccentColorBrush}" NonActiveBorderBrush="{DynamicResource AccentColorBrush}">
     <Grid>
         <Controls:MetroAnimatedSingleRowTabControl  Name="TabControl1"  Margin="0,0,0,0">
            <TabItem Header="Dashboard" Name="Dashboard">
                <Grid Margin="0,0,0,0">
                    <RadioButton HorizontalAlignment="Left" Margin="87,114,0,0" Name="RadioButton1" VerticalAlignment="Top" IsChecked="True" Width="64" Content="" VerticalContentAlignment="Center" />
                    <RadioButton HorizontalAlignment="Left" Margin="87,138,0,0" Name="RadioButton2" VerticalAlignment="Top" Width="64" />
                    <RadioButton HorizontalAlignment="Left" Margin="87,162,0,0" Name="RadioButton3" VerticalAlignment="Top" Width="64" />
                    <RadioButton HorizontalAlignment="Left" Margin="86,185,0,0" Name="RadioButton4" VerticalAlignment="Top" Width="64" />
                </Grid>
            </TabItem>
            <TabItem Header="Options" Name="Options">
                <Grid Margin="0,0,0,0" >

                </Grid>
            </TabItem>
            <TabItem Header="Info" Name="Info">
                 <Grid Margin="0,0,0,0">

                </Grid>
            </TabItem>
            <TabItem Header="Admin" Name="Admin">
                <Grid Margin="0,0,0,0" >

                </Grid>
            </TabItem>
            <TabItem Header="FM" Name="SuperAdmin">
                <Grid Margin="0,0,0,0" >

                </Grid>
            </TabItem>
        </Controls:MetroAnimatedSingleRowTabControl>
    </Grid>
</Controls:MetroWindow>

我使用自己的xaml-File(复制了原始的xaml-File并更改了Basic-Colors),但其余的都是相同的。

How it looks now

How it should be (Info is black because of MouseOver)

我现在如何将未选中的tabitems的默认前景颜色设置为灰色?

修改 能够找到问题:

我从应用程序MergedDictionaries中删除了BaseLight.xaml - 然后它再也没有用了 - 再次添加之后它再次运行。

之前:

<ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
            <!-- Accent and AppTheme setting -->
            <ResourceDictionary Source="LiquidStyle_Classic.xaml" />
       </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

后:

<ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
            <!-- Accent and AppTheme setting -->
            <ResourceDictionary Source="LiquidStyle_Classic.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

1 个答案:

答案 0 :(得分:0)

尝试使用自定义触发器为TabItem定义样式。 在网格中添加以下标记:

<Grid.Resources>
        <Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
            <Style.Triggers>
                <EventTrigger RoutedEvent="MouseEnter">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)"
                                            From="Gray" To="Black" Duration="0:0:1"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger RoutedEvent="MouseLeave">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)"
                                            From="Black" To="Gray" Duration="0:0:1"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    </Grid.Resources>