Reputation: 401
I am developing UWP app, and was trying to bind some property to primitive in XAML, and dont find how can I do it. I have a C# class with static values:
public class DevicePreferences
{
public static double InputTextFontSize = App.IsMobileDevice ? 22 : 18;
public static double TitleTextBoxSize = App.IsMobileDevice ? 20 : 16;
public static double ImageButtonSize = App.IsMobileDevice ? 40: 35;
}
and I was looking something like this:
<x:Double x:Key="MyCustomValue">{local:DevicePreferences.TitleTextBoxSize}</x:Double>
I am wondering, is there any way to do something like that?
Upvotes: 1
Views: 216
Reputation: 169200
If you set the DataContext
of whatever control you want to bind to the TitleTextBoxSize
property, you can bind to it directly as suggested here: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/e0e426ba-4feb-4571-b80b-7ba8818079b6/uwpstatic-property-binding?forum=wpdevelop
But you can't do something like this:
<x:Double x:Key="MyCustomValue">{local:DevicePreferences.TitleTextBoxSize}</x:Double>
You can only put constant double
values inside the <x:Double>
element.
Upvotes: 1