2017-11-26 31 views
0

MaterialDesignInXamlToolkitを使用して非常に単純なTextBoxスタイルをオーバーライドするのが難しいです。私の知る限り、私は手紙にoverride instructionsを追ってきた見ることができるようにMaterial Design XAMLオーバーライドスタイルが機能しない

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> 

ただし、オーバーライドファイルのスタイルからx:Keyを削除しない限り、テキストボックスのフォントは、スーパーエキサイティングではなく、非常に面白い12のままです。私は後です。

Github hereにサンプルプロジェクトを作成しました。誰かが見ていたら私はとても感謝しています。

答えて

3

問題は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>