【问题标题】:WPF - Assign static resources into XAML array without code-behindWPF - 将静态资源分配到 XAML 数组中,无需代码隐藏
【发布时间】:2018-05-21 07:33:53
【问题描述】:

我正在研究 MS .NET WPF;在 XAML 中,我定义了一些静态资源。我想将它们分配到一个也在 XAML 中声明的数组中。

这里是静态资源:

<local:Person x:Key="PersonABC" Name="Hello" Age="29" />
<local:Person x:Key="PersonXYZ" Name="World" Age="55" />

但我无法通过{StaticResource PersonABC} 之类的方式将它们分配到数组中。我必须重新创建资源并将它们分配到数组中:

<x:Array x:Key="PersonList" Type="{x:Type local:Person}">
    <local:Person Name="Hello" Age="29" />
    <local:Person Name="World" Age="55" />
</x:Array>

但我想要类似的东西:

<x:Array x:Key="PersonList" Type="{x:Type local:Person}">
    "{StaticResource PersonABC}"
    "{StaticResource PersonXYZ}"
</x:Array>

【问题讨论】:

    标签: wpf xaml staticresource


    【解决方案1】:

    StaticResource可以写成标签(元素)格式:

    <x:Array x:Key="PersonList" Type="{x:Type local:Person}">
        <StaticResource ResourceKey="PersonABC"/>
        <StaticResource ResourceKey="PersonXYZ"/>
    </x:Array>
    

    docs

    【讨论】:

      猜你喜欢
      • 2010-10-20
      • 2012-05-30
      • 2012-07-15
      • 2011-04-21
      • 2010-12-05
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 1970-01-01
      相关资源
      最近更新 更多