Skip to main content

Answered Question Load Resource Dictionalry dynamicallyRSS Feed

(0)

diptidjadhav
diptidja...

Member

Member

0 points

1 Posts

Load Resource Dictionalry dynamically

Hello,

I want to load resource dictionary file dynamically.

For eg. I have textbox  and i want to set its backgroup color dynamically from resource file.

in Test.xaml page:

 <TextBox  Text="Hello World" Style="{StaticResource HeaderTextblock}"></TextBox>

In Resource Dictionary 1: Blue.xaml

 <Style x:Name="HeaderTextblock"     TargetType="TextBox">       
        <Setter Property="Background" Value="Blue" />
    </Style>

In Resource Dictionary 2: Red.xaml

 <Style x:Name="HeaderTextblock"     TargetType="TextBox">       
        <Setter Property="Background" Value="Red" />
    </Style>

Already resource dictionary loaded as "Blue.xaml"

and on button click i want to load "Red.xaml"  so that textbox color will change as red.

Please suggest any way to do this. 

 

Thomas Claudius Huber
Thomas C...

Contributor

Contributor

7497 points

1,108 Posts

Answered Question

Re: Load Resource Dictionalry dynamically

Hi dipti,

you should look at the XamlReader-class and its Load-Method. But by the way, the StaticResource-Markup-Extension won't recognize any changes. It's just an initialization, but no binding (WPF contains another extension called DynamicResource. That one isn't available in Silverlight, so you've to refresh manually).

Thomas Claudius Huber
www.thomasclaudiushuber.com
  • Unanswered Question
  • Answered Question
  • Announcement