XAML Margin in resources

蓝咒 提交于 2019-12-11 13:58:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!