2015-12-04 66 views
11

我想在UWP上的XAML中訪問StaticResource變量的系統命名空間。 這裏的(大部分),我使用的是什麼:如何在UWP/RT XAML中聲明系統數據類型?

<Page 
    x:Class="App.UWP.Views.Step6" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:System="using:System" 
    mc:Ignorable="d"> 

    <Page.Resources> 
     <System:Double x:Key="ItemNameWidth">260</System:Double> 
    </Page.Resources> 

    <TextBlock FontSize="16" Width="{StaticResource ItemNameWidth}">foo</TextBlock> 
</page> 

即使<System:Double ...>顯示在智能感知是有效的,我得到以下運行時錯誤:

An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in mscorlib.ni.dll but was not handled in user code

WinRT information: Cannot deserialize XBF metadata type list as 'Double' was not found in namespace 'System'. [Line: 0 Position: 0]

我開放給其他如果此方法不起作用,則聲明爲double的方法。

回答

22

原來,它在默認的x:名稱空間中。

<Page 
    x:Class="App.UWP.Views.Step6" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:System="using:System" 
    mc:Ignorable="d"> 

    <Page.Resources> 
     <x:Double x:Key="ItemNameWidth">260</x:Double> 
    </Page.Resources> 

    <TextBlock FontSize="16" Width="{StaticResource ItemNameWidth}">foo</TextBlock> 
</page>