2017-12-16 33 views
0

私はMetroDarkテーマを使用しています。すべての要素のフォントファミリを変更する方法wpf-xaml

私は、XAMLでこのコードを使用します。

<Application.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="Theme/MetroDark/MetroDark.MSControls.Core.Implicit.xaml" /> 
       <ResourceDictionary Source="Theme/MetroDark/MetroDark.MSControls.Toolkit.Implicit.xaml" /> 
      </ResourceDictionary.MergedDictionaries> 
      <Style TargetType="{x:Type Label}" > 
       <Setter Property="FontFamily" Value="B titr" /> 
       <Setter Property="FontSize" Value="13" /> 
       <Setter Property="FontWeight" Value="Bold" /> 
      </Style> 
      <Style TargetType="{x:Type TextBox}" > 
       <Setter Property="FontFamily" Value="B Nazanin" /> 
       <Setter Property="FontSize" Value="16" /> 
       <Setter Property="FontWeight" Value="Bold" /> 
      </Style> 
     </ResourceDictionary> 
    </Application.Resources> 

フォントファミリは正しく変更されましたが、背景色があまりにも変更されました。

フォントファミリとフォントサイズ、および別のプロパティ(背景、枠線など)を変更し、デフォルトテーマ(MetroDark)から効果を得たいだけです。

どうすればいいですか?このようなBasedOn属性で

答えて

0

セットベースのスタイル:

<Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}"> 

<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}"> 

カスタムスタイルが基本スタイルからすべての設定を継承し、私はこのようなapp.xaml変更するが、それは線量それらのいくつか

0

を上書きすることができます。この方法うまくいかない。

<Application x:Class="Amlaak.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      StartupUri="frmProduct.xaml"> 

    <Application.Resources> 
     <ResourceDictionary>    
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="Theme/MetroDark/MetroDark.MSControls.Core.Implicit.xaml" /> 
       <ResourceDictionary Source="Theme/MetroDark/MetroDark.MSControls.Toolkit.Implicit.xaml" /> 
      </ResourceDictionary.MergedDictionaries> 
      <Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}"> 
       <Setter Property="FontFamily" Value="B titr" /> 
       <Setter Property="FontSize" Value="13" /> 
       <Setter Property="FontWeight" Value="Bold" /> 
      </Style> 
      <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}"> 
       <Setter Property="FontFamily" Value="B Nazanin" /> 
       <Setter Property="FontSize" Value="16" /> 
       <Setter Property="FontWeight" Value="Bold" /> 
      </Style> 
     </ResourceDictionary> 
    </Application.Resources> 
</Application>