2012-10-06 46 views

回答

1

您可以爲TargetType窗口創建一個全局樣式 並在那裏設置首選項。

資源:

<Application.Resources> 
    <Style TargetType="Window" x:Key="WindowStyle"> 
     <Setter Property="FontFamily" Value="{Binding FontFamilyPrefernce}" />      
    </Style>   
</Application.Resources> 

查看:

<Window Style="{StaticResource WindowStyle}"> 
     <Grid> 
      <TextBox /> 
     </Grid> 
</Window> 

視圖模型:

public SomeViewModel() 
    { 
     FontFamilyPrefernce = new FontFamily("Algerian"); 
    } 

    private FontFamily fontFamilyPrefernce; 
    public FontFamily FontFamilyPrefernce 
    { 
     get {return fontFamilyPrefernce ;} 
     set 
     { 
      fontFamilyPrefernce = value; 
      OnPropertyChanged("FontFamilyPrefernce"); 
     } 
    } 

希望這有助於..

相關問題