Hen*_*gen 3 xaml windows-runtime uwp
在Windows应用程序UWP项目,我试图将其分配给它的定义厚度Left,Top,Right和Bottom属性:
<Setter Property="Margin">
<Setter.Value>
<Thickness Left="{StaticResource SomeDouble}"
Top="0"
Right="0"
Bottom="0" />
</Setter.Value>
</Setter>
Run Code Online (Sandbox Code Playgroud)
这个答案似乎表明这在WPF中是可能的,但是,在我的UWP项目(以及WinRT应用程序)中,我收到以下错误:
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.
Run Code Online (Sandbox Code Playgroud)
有没有办法使用资源定义厚度?
你还可以.只System:Double改为x:Double.例如
<x:Double x:Key="SomeDouble">12</x:Double>
有趣的是,使用上面的xaml设计师显示正常,但它不编译...是的它给出了与你所展示的完全相同的错误.
所以我想你必须Thickness在xaml中定义整体.
<Thickness x:Key="Thickness1">12,0,0,0</Thickness>
<Setter Property="Margin" Value="{StaticResource Thickness1}" />
Run Code Online (Sandbox Code Playgroud)
我这次运行了这个项目,是的.:)