问题
How do I define XAML margin in Windows universal app resources? I tried to define it as
<Thickness x:Key="MyMargin" Left="10" Top="20" Right="10" Bottom="20" />
by this does not compile, I get
XamlCompiler error WMC0100: XAML Thickness type cannot be constructed. In order to to be constructed in XAML, a type cannot be abstract, interface, nested, generic or a struct, and must have a public default constructor
回答1:
The syntax for Windows XAML is as follows:
<Thickness x:Key="myMargin">10,20,10,20</Thickness>
which could be simplified to:
<Thickness x:Key="myMargin">10,20</Thickness>
回答2:
I had it working by binding it to a String:
<x:String x:Key="MarginLeftPage" >120,0,0,0</x:String>
[...]
Grid Margin="{StaticResource MarginLeftPage}">
来源:https://stackoverflow.com/questions/30238734/xaml-margin-in-resources