views:

206

answers:

2

If you put style in app.xmal, then you can get the style with the code like:

Style = Application.Current.Resources["myStyle"] as Style;

But if I put style in a dictionary resource of a separate file Styles.xmal like:

 <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>                
                <ResourceDictionary Source="Assets/Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

Then how to get the style in code?

A: 

Find out reaosn: code

Style = Application.Current.Resources["myStyle"] as Style;

works fine. My problem is caused by some other factors.

KentZhou
A: 

tip:

  • be careful not to do this.Resources for the current object by mistake if what you're looking for is in Styles.xaml or Resources.xaml
  • also don't expect to see all the resources in the 'add watch' dialog for Application.Current.Resources. ones defined in XAML won't be there (at least not on the top level)
Simon_Weaver

related questions