首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XAML覆盖样式的材料设计不工作

XAML覆盖样式的材料设计不工作
EN

Stack Overflow用户
提问于 2017-11-26 16:43:15
回答 1查看 9.2K关注 0票数 3

我在使用TextBox重写非常简单的MaterialDesignInXamlToolkit样式时遇到了困难。

据我所见,我一直在跟踪覆盖指令

App.xaml

代码语言:javascript
复制
<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

代码语言:javascript
复制
<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

代码语言:javascript
复制
<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>

但是,除非我从重写文件中的样式中删除x:Key,否则文本框中的字体将保持在非常无聊的12,而不是我想要的超级令人兴奋的200

我在Github这里上创建了一个示例项目。如果有人能看一看,我会非常感激的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-26 17:31:46

问题出现在MaterialDesignTheme.Overrides.xaml上。您指定要重写的特定样式,但不引用包含该样式的资源字典。将其合并将解决问题。

代码语言:javascript
复制
<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>
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47498540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档