gpt4 book ai didi

material-design-in-xaml - XAML 中的 Material 设计覆盖样式不起作用

转载 作者:行者123 更新时间:2023-12-04 16:46:50 25 4
gpt4 key购买 nike

我在使用 MaterialDesignInXamlToolkit 覆盖一个非常简单的 TextBox 样式时遇到了困难。

据我所知,我已关注 override instructions信中:

App.xaml

<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="Themes/MaterialDesignTheme.Overrides.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

MainWindow.xaml

<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:materialDesign="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
Title="MainWindow" Height="400" Width="300">
<Grid>
<TextBox VerticalAlignment="Center"
x:Name="NameTextBox"
materialDesign:HintAssist.Hint="Name">
</TextBox>
</Grid>
</Window>

MaterialDesignTheme.Overrides.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:materialDesign="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf">

<Style x:Key="MaterialDesignTextBox"
BasedOn="{StaticResource MaterialDesignTextBox}"
TargetType="{x:Type TextBox}">
<Setter Property="FontSize" Value="200" />
</Style>

</ResourceDictionary>

但是,除非我从 overrides 文件中的样式中删除 x:Key,否则文本框中的字体会停留在非常无聊的 12,而不是 super 令人兴奋的 200 我在追。

我在 Github here 上创建了一个示例项目.如果有人能看一下,我将不胜感激。

最佳答案

问题出在 MaterialDesignTheme.Overrides.xaml 中。您正在指定要覆盖的特定样式,但未引用包含该样式的资源字典。将其合并将解决问题。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBox.xaml" />
</ResourceDictionary.MergedDictionaries>

<Style BasedOn="{StaticResource MaterialDesignTextBox}"
TargetType="{x:Type TextBox}">
<Setter Property="FontSize" Value="200" />
</Style>
</ResourceDictionary>

关于material-design-in-xaml - XAML 中的 Material 设计覆盖样式不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47498540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com