问题:
I'm trying to access the system namespace for StaticResource variables in XAML on UWP. Here's (mostly) what I'm using:
<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"></System:Double>
</Page.Resources>
<TextBlock FontSize="" Width="{StaticResource ItemNameWidth}">foo</TextBlock>
</page>
Even though the <System:Double ...> shows in IntelliSense as valid, I'm getting the following runtime error:
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: Position: ]
I'm open to other ways of declaring a double if this method will not work.
解决方案:
Turns out it's in the default x: namespace.
<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"></x:Double>
</Page.Resources>
<TextBlock FontSize="" Width="{StaticResource ItemNameWidth}">foo</TextBlock>
</page>