2014-11-23 74 views
0

为什么此代码给出错误: 名称空间xmlns中不存在名称字典:scg =“clr-namespace:System.Collections.Generic; assembly = mscorlib”。在xaml代码中创建字典

<Window x:Class="Test.MainWindow" 
     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" 
     xmlns:test="clr-namespace:Test" 
     Title="MainWindow" Height="350" Width="525"> 

    <Window.Resources> 
     <scg:Dictionary x:Key="CountryPopulRecords" TypeArguments="sys:String,sys:String"></scg:Dictionary> 
    </Window.Resources> 

    <Grid> 

    </Grid> 
</Window>  

参考:MSDN

回答

0

也许这可以帮助: Create a Dictionary in xaml?

你不能在XAML中直接使用Dictionary类,因为没有办法来指定泛型类型参数(它可能会在下一个版本的XAML中使用,但它不会在VS2010 WPF设计器中受到支持......至少在初始版本中不会)。

但是,您可以声明从Dictionary继承的非泛型类,并在XAML中使用它。

+0

我已经使用基于此MSDN链接的代码:[link](http://msdn.microsoft.com/en-us/library/ms750476(v = vs.110).aspx) – AnjumSKhan 2014-11-23 10:53:19

+0

你有没有读过整个文章? (我的链接和你的链接)? – ZSH 2014-11-23 11:04:12

+1

用两个String类型实参实例化一个新的Dictionary 。 – AnjumSKhan 2014-11-23 11:26:02