Skip to content

Features: Strongly typed properties

Rudy Huyn edited this page Aug 20, 2019 · 3 revisions

ReswPlus generates a class exposing all strings from your .resw files as strongly typed static properties, providing a compile-time-safe way to access those strings XAML-side or code-side.

Contrary to ResourceLoader.GetString("IdString"), the compiler will verify how your XAML and C# access your strings and will fail the compilation if a resource doesn't exist.

This feature will allow you to localize your applications using bindings (including native bindings) and code-behind (similar to .resx files in WPF/Silverlight applications) and will allow you to use converter, functions, etc...

The recommended way to access localization strings in your XAML is using native bindings. When native binding isn't possible (ResourceDictionary, control template...) ReswPlus provides an alternative way to access to resources via custom MarkupExtension (verified at compilation time).

Code generated:

public class Resources {
    private static ResourceLoader _resourceLoader;
    static Resources()
    {
        _resourceLoader = ResourceLoader.GetForViewIndependentUse();
    }
    public static string WelcomeTitle => _resourceLoader.GetString("WelcomeTitle");
}

How to use it:

XAML - native binding:

<TextBlock Text="{x:Bind strings:Resources.WelcomeTitle}" />

XAML - special markup (generated by ReswPlus):

<TextBlock Text="{strings:Resources Key=WelcomeTitle}" />

Code behind:

titlebar.Title = Resources.WelcomeTitle;

These 3 ways are compile-time verified.