2016-04-13 24 views
0

我試圖創建一個類型GridLength的StaticResource以在我的XAML中使用。我想定義統一寬度的列,但我似乎無法在Xaml中找到允許我定義StaticResource的Namespace。在文檔中,我發現GridLength結構存在於這個命名空間Windows.UI.Xaml;然而,當我嘗試在我的Xaml文件的頂部包含名稱空間時,我似乎無法找到它。用於創建GridLength的StaticResource的命名空間

這是我的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.我是否正確使用屬性?我在文檔中找到它,但不知道如何正確使用它。

+0

[在WPF中指定寬度/高度作爲資源]的可能副本(http://stackoverflow.com/questions/2279732/specify-width-height-as-resource-in-wpf) –

+1

本節解釋如何定義GridLength資源:http://stackoverflow.com/a/18637378/1023619 – lexa

+1

您不需要任何名稱空間。只是' 50'什麼是'property =「doubleLength」'所有關於? –

回答

1

您不需要任何命名空間,因爲Windows.UI.Xaml是默認值。只是這個:

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

會做得很好。

1

正如Ed指出的那樣,我不需要使用名稱空間來聲明GridLength的StaticResource。我只需輸入:<GridLength x:Key="MyColumnWidth">50</GridLength>