where should dialog box strings be stored?

You shouldn’t use resource dictionaries (xaml) to store text. Instead you have to use Resources (*.resx). In VS:

  1. Right click on project
  2. Add -> New Item…
  3. Find “Resources File” template, type name, and click Add
  4. Opt. Open this file (special editor will opened) and on top bar switch Access Modifier to Public, if you want get access to text from another project or from XAML. Add some key\value strings.
  5. Right click on resource file and click Run Custom Tool. New class will generated with static properties with names based on your keys from Step 4.

How to use (if file has name Localizations.resx and has string with key “AppTitle”)

From code:

let! closeDlgAction = 
            dialogSvc.ShowDialogModeless (
                Localizations.AppTitle,
                "Please wait while your selected file is opened.") |>  Async.AwaitTask

From xaml:

<Window
    x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="{x:Static Localizations.AppTitle}"/>

*.resx file and *.cs file that is generated both don’t depend on any WPF assemblies, so you can use them in different assemblies: in shared view models, from wpf views and from xamarin views. Just put you *.resx file in separate netstandard assembly and refer to it where do you need it from enter image description here

Cons of this way:

  1. resx generates class with strings and each string is public property, so static code analyze works
  2. You don’t have add new abstraction level
  3. You can ref strings from code files or from XAML

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top