2015-12-04 17 views
11

Tôi đang cố gắng truy cập vào không gian tên hệ thống cho các biến StaticResource trong XAML trên UWP. Dưới đây là (chủ yếu) những gì tôi đang sử dụng:Làm cách nào để khai báo kiểu dữ liệu Hệ thống trong 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> 

Mặc dù <System:Double ...> show trong IntelliSense là hợp lệ, tôi nhận được lỗi runtime sau:

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]

Tôi mở cửa cho khác cách khai báo gấp đôi nếu phương thức này không hoạt động.

Trả lời

22

Biến nó thành không gian tên mặc định là 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> 
Các vấn đề liên quan