Nidx
Nidx

Reputation: 73

Binding FontFamily ViewModel's Property

I want to bind the FontFamily of a TextBox to a property I created on my ViewModel

Here's my XAML :

<TextBox Text="Test Font Binding" FontFamily="{Binding FontFirstContent}" />

And here the property in my ViewModel :

public FontFamily FontFirstContent
{
    get { return new FontFamily("Verdana"); }
}

When the view is loaded, the getter of the property is correctly firing but it's not passed on the view. All bindings on my view are working except this one, so i don't understand what's wrong with it ?

Edit : Okay it works fine ! I was just working on the wrong FontFamily object.. I've used :

System.Drawing.FontFamily

But the FontFamily must be of type :

System.Windows.Media.FontFamily

Upvotes: 6

Views: 1936

Answers (1)

trinaldi
trinaldi

Reputation: 2950

Here's something I added to a ResourceDictionaryintended to be a default style for my application:

<FontFamily x:Key="MyFontFamily">Segoe UI</FontFamily>

When you want to use it, you set the FontFamily property like this:

<Label Content="Something" FontFamily="{DynamicResource MyFontFamily}"/>

Don't forget to put it in a ResourceDictionary or any Control Resource.

Hope it helps;

Upvotes: 1

Related Questions