In a windows UWP app project, I am trying to define a Thickness by assigning to its Left
, Top
, Right
and Bottom
properties:
<Setter Property="Margin">
<Setter.Value>
<Thickness Left="{StaticResource SomeDouble}"
Top="0"
Right="0"
Bottom="0" />
</Setter.Value>
</Setter>
This answer seems to suggest that this is possible in WPF, however, in my UWP project (as well as in a WinRT app), I get the following error:
XAML Thickness type cannot be constructed.
In order to be constructed in XAML, a type cannot be abstract, interface, nested, generic
or a struct, and must have a public default constructor.
Is there a way to define the Thickness using resources?
You still can. Only to change System:Double
to x:Double
. e.g.
<x:Double x:Key="SomeDouble">12</x:Double>
Interesting, with the above xaml the designer shows up fine but it doesn't compile... Yes it gives the exact same error like you showed.
So I guess you have to define the whole Thickness
in xaml.
<Thickness x:Key="Thickness1">12,0,0,0</Thickness>
<Setter Property="Margin" Value="{StaticResource Thickness1}" />
I ran the project this time and yeah it worked. :)
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