4

I want to define some resources in my App.Xaml for fontsize.

This type of thing will work:

   <sys:Double x:Key="FontLarge">24</sys:Double>

But I want to get the value from a :xStatic so something like this:

<sys:Double x:Key="FontLarge">{x:Static local:Settings.FontLarge</sys:Double>

or

<sys:Double x:Key="FontLarge" Value="{x:Static local:Settings.FontLarge"></sys:Double>

Neither of these work though. Is this possible and what would be the syntax?

  • Rather than defining double in xaml, you can use the x:static in the binding itself. i.e where you're planning to use FontLarge, just use x:Static local:Settings.FontLarge ? – Sriram Sakthivel Jan 14 '16 at 07:55
  • I could but I;d have to change a lot of stuff in my markup. Doing it this way means I only need to define it in one place. – Jeff - Software Results Jan 14 '16 at 08:02
  • Are you referencing the resource statically by `FontSize="{StaticResource FontLarge}"` or rather bind it with `FontSize="{Binding Source={StaticResource FontLarge}}"`? – Grx70 Jan 14 '16 at 08:19
  • Referring to it statically as per your first example. I've been able to use the x:Static approach for things like brushes where the Color property is the x:Static value. It's just the low level double and string type values I'm having an issue with. – Jeff - Software Results Jan 14 '16 at 08:58

1 Answers1

0

I don't think that there is a way to bind Double value using x:Static (I may be wrong though).

But there is always a way using code behind which you can use. If this is meant to be in App.Xaml, you can write

App.Current.Resources.Add("FontLarge", Settings.FontLarge);

If some other class, you can just drop the App.Current and that would work.

Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189