Search code examples
wpfxaml

Define a string as a static resource


Is there a way to define a constant string to be used as a static resource across the whole application?

I am running a WPF application but there is no main XAML form. The application is a collection of XAML controls handled by a single classic .cs Form.


Solution

  • Just add a resource dictionary XAML file, let's say it's named Dictionary.xaml (Visual Studio can create you one automatically).

    Then, add your static resource in this dictionary.

    To finish, reference the dictionary in all your XAML controls:

    <UserControl.Resources>
        <ResourceDictionary Source="Dictionary.xaml"/>
    </UserControl.Resources>