在 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.
有没有办法使用资源来定义厚度?
最佳答案
你还可以。只为改System:Double
至 x:Double
.例如<x:Double x:Key="SomeDouble">12</x:Double>
更新
有趣的是,使用上面的 xaml,设计器显示良好,但无法编译...是的,它给出了与您显示的完全相同的错误。
所以我猜你必须定义整个 Thickness
在 xml 中。
<Thickness x:Key="Thickness1">12,0,0,0</Thickness>
<Setter Property="Margin" Value="{StaticResource Thickness1}" />
这次我运行了这个项目,是的,它奏效了。 :)
关于xaml - 使用资源定义厚度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35149204/