[SOLVED] How to use Converters without binding value


This Content is from Stack Overflow. Question asked by GeorgeKarlinzer

maybe my question is stupid, but is it possible to use converters for string literals without binding to value? In my case converter is used for translation (literal (key in resx) is text in default language and converted value is translated text).

  1. I can create string property inside my ViewModel, but there are a lot of such literals, and it can make a mess in view model.
  2. Another solution is to bind value directly to resx:
<TextBlock Text="{x:Static SomeResxFile.Employees, Converter=...}" />

But there can be spaces in my resx key, so this approach does not work.

I do not want to create property for every label in my app, but I also want to use strings with spaces as key in my resx.

What I want to reach:

<TextBlock Text="{Binding Value="Add employee", Converter=...}" />


you can use Binding extension (to get advantage of converter) by explicitly setting binding Source (without using DataContext):

<TextBlock Text="{Binding Source='Add employee', Converter={StaticResource SomeConverter}}" />

or reference project resources:

<TextBlock Text="{Binding Source={x:Static SomeResxFile.Employees}, Converter={StaticResource SomeConverter}}" />

This Question was asked in StackOverflow by GeorgeKarlinzer and Answered by ASh It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?