Search code examples
wpfxamlxml-namespacesstaticresourcegridlength

Namespace for creating StaticResource of GridLength


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.


Solution

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

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

    Will do fine.