Problem with x: TypeArguments and a generic List class in XAML

I created the following markup for a free XAML file.

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"> <scg:List x:TypeArguments="sys:String"> HelloWorld </scg:List> </StackPanel> 

But I get this error when I run free XAML in IE:

The 'List' tag does not exist in the XML namespace 'clr-namespace: System.Collections.Generic; assembly = mscorlib '. Line '7' Position 2 '.

As you know, generics in XAML are a feature of XAML 2009 and can only work for the most part in free XAML files. But the above code does not work.

Is it possible to understand why this error occurred and how to fix this problem? Thanks in advance.

+8
generics c # xaml
source share
2 answers

The problem is resolved. I needed to include the following namespace mapping in the markup to enable generics.

XMLNS: v4 = "http://schemas.microsoft.com/netfx/2009/xaml/presentation"

Now it works great.

+2
source share

I just checked your sample with Internet Explorer 9. IE9 uses PresentationHost.exe to display the content and my system (Windows 7 SP1 x64), and by researching which assemblies are really loaded, I confirmed that I am using the v3.0 frame, which is not supports XAML 2009.

The documentation describes that for XBAP it selects the version of the framework to download, and therefore it can explicitly use the v4.0 framework, which supports XAML 2009 for free XAML. However, the documentation, unfortunately, does not indicate which version of the frame it will choose for free XAML, unlike XBAP.

Empirically, at least with your sample, I can confirm that PresentationHost.exe chooses the v3.0 frame. I cannot find a way to override this choice, for example, annotating XAML.

+3
source share

All Articles