【问题标题】:Namespace for creating StaticResource of GridLength用于创建 GridLength 的 StaticResource 的命名空间
【发布时间】: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属性?我在文档中找到了它,但不确定如何正确使用它。

【问题讨论】:

标签: wpf xaml xml-namespaces staticresource gridlength


【解决方案1】:

您不需要任何命名空间,因为Windows.UI.Xaml 是默认值。就是这样:

<GridLength x:Key="MyColumnWidth">50</GridLength> 

会做得很好。

【讨论】:

    【解决方案2】:

    正如 Ed 指出的,我不需要使用名称空间来声明 GridLength 的 StaticResource。我所要做的就是输入:&lt;GridLength x:Key="MyColumnWidth"&gt;50&lt;/GridLength&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      • 2018-11-02
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      • 2016-07-15
      相关资源
      最近更新 更多