wpf 为我的标题 Tabitem 覆盖 Mahapps Metro 风格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23377194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 11:40:03  来源:igfitidea点击:

Overwrite Mahapps Metro style for me header Tabitem

c#wpfxamlmvvmmahapps.metro

提问by CampDev

I am working with WPF and MVVM. I installed Mahapps Metro, this nuget package provides all styles for my app.

我正在使用 WPF 和 MVVM。我安装了 Mahapps Metro,这个 nuget 包为我的应用程序提供了所有样式。

I made a TabControl, but the FontSize that Mahapps uses for the header in each TabItem is very big for my application.

我制作了一个 TabControl,但是 Mahapps 用于每个 TabItem 中的标题的 FontSize 对我的应用程序来说非常大。

I need to create a StaticResource that changes the FontSize of the header in a TabItem without removing others properties that Mahapps provides.

我需要创建一个 StaticResource 来更改 TabItem 中标题的 FontSize 而不删除 Mahapps 提供的其他属性。

回答by DR.

Put the following code in your window's resources like:

将以下代码放在窗口的资源中,例如:

<Window
......
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
......
>
<Window.Resources>
        <Style x:Key="MenuLevel2" BasedOn="{StaticResource MetroTabItem}" TargetType="{x:Type TabItem}">
            <Setter Property="mah:ControlsHelper.HeaderFontSize" Value="24"></Setter>
        </Style>
<Window.Resources>

Looking at the source code [ https://github.com/MahApps/MahApps.Metro/blob/master/MahApps.Metro/Styles/Controls.TabControl.xaml,at line 158] you can see that the programmers made a special exception to set this property, because the font is in a Control Template, inside a Content Presenter. It is easier to set ControlsHelper.HeaderFontSize property.

查看源代码 [ https://github.com/MahApps/MahApps.Metro/blob/master/MahApps.Metro/Styles/Controls.TabControl.xaml, at line 158] 你可以看到程序员做了一个特殊的例外设置此属性,因为字体位于内容展示器内的控件模板中。设置 ControlsHelper.HeaderFontSize 属性更容易。

回答by Praveen M B

As suggested in the above answer, put the below code in Window.Resources

正如上面的答案所建议的,将下面的代码放在 Window.Resources 中

    <Window
......
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
......
>
<Window.Resources>
        <Style x:Key="MenuLevel2" BasedOn="{StaticResource MetroTabItem}" TargetType="{x:Type TabItem}">
            <Setter Property="mah:ControlsHelper.HeaderFontSize" Value="15"></Setter>
        </Style>
<Window.Resources>

In the TabItem section add the style details.

在 TabItem 部分添加样式详细信息。

<TabItem Header="Dimension Alias" Style="{DynamicResource MenuLevel2}">

This worked for me.

这对我有用。