Mar*_*kNS 2 material-design-in-xaml
我在使用 MaterialDesignInXamlToolkit 覆盖非常简单的 TextBox 样式时遇到了困难。
应用程序.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>
Run Code Online (Sandbox Code Playgroud)
主窗口.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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
但是,除非我x:Key从覆盖文件中的样式中删除 ,否则文本框中的字体将保持非常无聊的 12,而不是我追求的超级令人兴奋的200。
问题出在 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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7415 次 |
| 最近记录: |