1

如何在 c# 中将字体系列的用户首选项设置为 wpf mvvm 应用程序?

4

1 回答 1

2

您可以为 TargetType Window 创建一个全局 Style 并在那里设置 Preference 。

资源:

<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");
        }
    }

希望这可以帮助 ..

于 2012-10-06T13:30:13.167 回答