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
Here's something I added to a ResourceDictionary
intended 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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With