I want to simplify bindings in WPF. Say, I'm creating a FontFamily
resource in App.xaml which binds to a string value in the application settings, to avoid a long line of binding expression in every window. But I found that I couldn't find a way to do that.
It is said that there's a x:Arguments
in XAML 2009, but that does not apply here.
My approaches:
<DynamicResource x:Key="PrimaryFont" ResourceKey="{Binding PrimaryFont, Source={x:Static properties:Settings.Default}, Converter={StaticResource StringToFontFamilyConverter}}"/>
failed, throwing an XamlParseException
.
<FontFamily x:Key="PrimaryFont">
<Binding Path="PrimaryFont" Source="{x:Static properties:Settings.Default}" Converter="{StaticResource StringToFontFamilyConverter}"/>
</FontFamily>
this even does not compile.
I don't want to add that in code behind, because I don't want to make everything look like a mess. Is that possible?
EDIT: this is not a duplicate of Setting global font family. The FontFamily
is just for explaining purpose, in real world there will be more than one kind of element I want to simplify the binding on, and the element might not be a good target for a new style.