Default ValueConverter for a class in WPF

I am going to start a new project, and currently I am evaluating some methods of localization, modularity, etc.

I have (at least in my opinion) a pretty good approach to localization, but now I'm trying my best to find a good solution for data binding.

I want to bind the values โ€‹โ€‹of text fields, etc. (in general, UIElements) to a specific method in the DataContext of the form. The method is as follows:

public void GetValue(string name)

where name is the "path" in the form of "node / subnode / subsubnode". I was thinking about using ValueConverter for binding, and so far it has been very nice.

My required expression is as follows:

{Binding Path=Localization, Converter={StaticResource LocalizationConverter}, ConverterParameter=PrismBreak/Shell.xaml/New}

I think this mandatory expression, although it does its job, is blown up to use it for every UIElement. So I thought, is it possible to determine the default ValueConverter value for a particular type (-> whenever this type is bound to where ValueConverter is used).

Is this possible in WPF?

If this is not possible, is there another good way to bind to a method with dynamic parameters?

Thanks in advance and best regards,

Chris

+1
source share
1 answer

The prescribed way to perform localization for WPF is to create a localized BAML in satellite assemblies; this is achieved by adding the x: Uid property to the elements you would like to localize. MSDN describes the WPF Partition technology for globalization and localization .

Another approach that I would suggest would be to create a static dictionary "Localization Dictionary" and implement ICustomTypeDescriptor to redirect the incoming property associated with the strings in your dictionary. You could do something like this:

 <Button Content=" {Binding Source={x:Static local:MyStaticType.Localization}, Path=HelloButtonTitle}" /> 

And you can continue to use existing technologies such as RESX + Satellite assemblies.

+3
source

Source: https://habr.com/ru/post/1286133/


All Articles