【发布时间】:2016-04-14 11:40:50
【问题描述】:
我正在尝试创建 GridLength 类型的 StaticResource 以在我的 XAML 中使用。我想定义统一宽度的列,但我似乎无法在 Xaml 中找到允许我定义我的 StaticResource 的命名空间。在文档中,我发现该命名空间 Windows.UI.Xaml 下存在 GridLength 结构;但是,当我尝试在我的 Xaml 文件顶部包含名称空间时,我似乎找不到它。
这是我的 XAML:
<UserControl ...
xmlns:windows="clr-namespace:System.Windows.UI.Xaml;" >
<UserControl.Resources>
<windows:GridLength property="doubleLength" x:Key="MyColumnWidth">50</windows:GridLength>
</UserControl.Resources>
...
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource MyColumnWidth}"/>
<ColumnDefinition Width="{StaticResource MyColumnWidth}"/>
<ColumnDefinition Width="{StaticResource MyColumnWidth}"/>
</Grid.ColumnDefinitions>
....
</Grid>
</UserControl>
这是我的问题: 1. 我使用什么命名空间? 2. 如何声明 GridLength StaticResource? 3.我是否正确使用了property属性?我在文档中找到了它,但不确定如何正确使用它。
【问题讨论】:
-
这个解释如何定义GridLength资源:stackoverflow.com/a/18637378/1023619
-
你不需要任何命名空间。只是
<GridLength x:Key="MyColumnWidth">50</GridLength>property="doubleLength"是什么? -
你解决了我的问题!将此写为答案,我会将其标记为解决方案。
标签: wpf xaml xml-namespaces staticresource gridlength