2017-11-26 19 views
0

MaterialDesignInXamlToolkit을 사용하여 매우 간단한 TextBox 스타일을 재정의하는 데 어려움을 겪고 있습니다.재질 디자인 XAML 무시 스타일이 작동하지 않습니다.

지금까지 내가 편지에 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> 

그러나 무시 파일의 스타일에서 x:Key을 제거하지 않으면 텍스트 상자의 글꼴이 매우 흥분하지 않고 1230으로 유지됩니다. 이후입니다.

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>