如何在 C# 中将字体系列的用户首选项设置为 wpf mvvm 应用程序?
您可以为目标类型窗口创建全局样式并在那里设置了首选项.
资源 :
<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");
}
}
希望这有帮助..