Question

How to set User Preferences for font family to a wpf mvvm application in c#?

Was it helpful?

Solution

you can create a global Style for TargetType Window and there set the Preference .

the resource :

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

the View :

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

the ViewModel :

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

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

hope this helps ..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top