BCA
BCA

Reputation: 8506

How is a static resource referenced in a XAML collection?

If I have static resources defined in XAML such as

<x:String x:Key="HelloString">Hello</x:String>
<x:String x:Key="GoodbyeString">Goodbye</x:String>

What is the syntax to add them to a XAML collection such as ListBox?

My intent would be to do something like this:

<ListBox>
    <x:String Source="{StaticResource HelloString}"/>
    <x:String Source="{StaticResource GoodbyeString}"/>
</ListBox>

But I'm missing the correct syntax.

Upvotes: 0

Views: 188

Answers (1)

Michael Mairegger
Michael Mairegger

Reputation: 7301

It is possible by using a ContentPresenter:

<ListBox>
    <ContentPresenter Content="{StaticResource HelloString}"/>
    <ContentPresenter Content="{StaticResource GoodbyeString}"/>
</ListBox>

Upvotes: 3

Related Questions