Reputation:

How to bind resources string to Xaml in Silverlight

How do you bind resources string to Xaml in Silverlight?

Upvotes: 3

Views: 4787

Answers (2)

SondreB
SondreB

Reputation: 808

Been a while since this was asked and answered, I just wanted to add an additional answer as the first one is not entirely correct. I think he's asking for resources, aka. text written in .resx files. It doesn't make sense at all to add individual strings into the StaticResources collection in the application.

I blogged recently on how to simplify the way you work with resources in Silverlight, enabling both automatic update when the culture changes and a dependency property which gives you simpler syntax.

http://sondreb.com/blog/post/Simplifying-Text-Resources-in-Silverlight.aspx

Upvotes: 2

Jon Morley-Jones
Jon Morley-Jones

Reputation: 61

You need to add this reference to the App.xaml

xmlns:sys="clr-namespace:System;assembly=mscorlib" 

Then you need to add the string into the <Application.Resources> section

<sys:String x:Key="ResourceString">Resource String</clr:String>

Then all you need to do is refer to *{StaticResource ResourceString} for example:

<TextBlock Text="{StaticResource ResourceString}"></TextBlock>

Upvotes: 6

Related Questions