在Windows UWP应用项目中,我尝试通过分配其Left
,Top
,Right
和Bottom
属性来定义厚度:
<Setter Property="Margin">
<Setter.Value>
<Thickness Left="{StaticResource SomeDouble}"
Top="0"
Right="0"
Bottom="0" />
</Setter.Value>
</Setter>
This answer似乎表明这在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.
有没有办法使用资源定义厚度?
答案 0 :(得分:6)
你还可以。仅将System:Double
更改为x:Double
。 e.g。击>
<击> <x:Double x:Key="SomeDouble">12</x:Double>
击>
有趣的是,使用上面的xaml设计器显示正常,但它不能编译...是的,它会给出与您所显示的完全相同的错误。
所以我想你必须在xaml中定义整个Thickness
。
<Thickness x:Key="Thickness1">12,0,0,0</Thickness>
<Setter Property="Margin" Value="{StaticResource Thickness1}" />
这次我运行了这个项目,是的。 :)