WPF - Assign static resources into XAML array without code-behind
Asked Answered
T

1

5

I'm working on MS .NET WPF; In XAML, I've defined some static resources. I want to assign them into an array which is also declared in XAML.

Here are the static resources:

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

But I couldn't assign them into the array by something like {StaticResource PersonABC}. I've to re-create the resources and assign them into the array:

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

But i want something like:

<x:Array x:Key="PersonList" Type="{x:Type local:Person}">
    "{StaticResource PersonABC}"
    "{StaticResource PersonXYZ}"
</x:Array>
Towney answered 21/5, 2018 at 7:33 Comment(0)
C
7

StaticResource can be written in tag (element) format:

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

see docs

Christiniachristis answered 21/5, 2018 at 7:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.