【问题标题】:Creating a Dictionary in xaml code在 xaml 代码中创建字典
【发布时间】:2014-11-23 08:19:14
【问题描述】:

为什么这段代码会出错: 命名空间 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

【问题讨论】:

    标签: wpf xaml dictionary


    【解决方案1】:

    也许这会有所帮助: Create a Dictionary in xaml?

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

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

    【讨论】:

    • 我使用了基于此 MSDN 链接的代码:link
    • 用两个 String 类型参数实例化一个新 Dictionary
    猜你喜欢
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多