如何在UWP / RT XAML中声明系统数据类型?

时间:2015-12-04 18:07:58

标签: c# xaml winrt-xaml uwp windows-10-universal

我正在尝试在UWP上的XAML中访问StaticResource变量的系统命名空间。 这是(大部分)我正在使用的东西:

console.log('I'm still here');

即使<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> 在IntelliSense中显示为有效,我也会遇到以下运行时错误:

  

mscorlib.ni.dll中出现“Windows.UI.Xaml.Markup.XamlParseException”类型的异常,但未在用户代码中处理

     

WinRT信息:无法反序列化XBF元数据类型列表,因为在命名空间“System”中找不到“Double”。 [行:0位置:0]

如果这种方法不起作用,我会采用其他方式声明双重。

1 个答案:

答案 0 :(得分:25)

原来它在默认的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>