Namespace for creating StaticResource of GridLength

822 Views Asked by At

I'm trying to create a StaticResource of the type GridLength to use in my XAML. I want to define columns of uniform width, but I cannot seem to find the Namespace in Xaml that allows me to define my StaticResource. In the documentation, I have found the the GridLength struct exists under this namespace Windows.UI.Xaml; however, I cannot seem to find it when I try to include the name space at the top of my Xaml file.

Here is my 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>

Here are my questions: 1. What namespace do I use? 2. How do I declare a GridLength StaticResource? 3. Am I using the property attribute correctly? I found it in the documentation but am not sure how to use it appropriately.

2

There are 2 best solutions below

0
On BEST ANSWER

You don't need any namespace, because Windows.UI.Xaml is the default. Just this:

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

Will do fine.

0
On

As Ed pointed out, I do not need to use a name space to declare a StaticResource of GridLength. All I had to do was type:<GridLength x:Key="MyColumnWidth">50</GridLength>