在xaml代码中创建字典

时间:2014-11-23 08:19:14

标签: wpf xaml dictionary

为什么此代码出错: 名称字典在命名空间xmlns中不存在:scg =" clr-namespace:System.Collections.Generic; assembly = mscorlib"

<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

1 个答案:

答案 0 :(得分:0)

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

  

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

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