winrt-xaml

How do I reference a StaticResource in code-behind?


In XAML I do it like this:

<Button Style="{StaticResource NavigationBackButtonNormalStyle}" />

How do I do the same thing in code-behind?


Solution

  • The page-level Resources object has the ability to find local, app-level, static, and theme resources. This means you simply do this:

    foo2.Style = this.Resources["NavigationBackButtonNormalStyle"] as Style;
    

    Best of luck!