freewill
freewill

Reputation: 1171

wpf element name as an argument for IValueConverter

I am trying to get multilingual translation("label or caption") string value for the given elementname in wpf. For example; for elementname "txtDescription" ; my IValueConverter implementation will return with "Description" ; for another language will return different translation string(i.e. descripción for Spanish) and the translation string will be Text=... of the same element.

I am new to wpf; I cant make it work. Is there any elegant way to do that with similiar manner as below.

<TextBlock Name="txtDescription" Text="{Binding Converter={StaticResource MultiLingualConverter} }"</TextBlock>

If this is not simple or requires more code then as an alternative sending "txtDescription" as an argument to MultiLingualConverter is acceptable but I dont now how to do that neither.

Upvotes: 0

Views: 411

Answers (3)

Ben Cohen
Ben Cohen

Reputation: 1410

Definitely, you should build good localization support in your system, better then using converter for every string.

Until today, the best solution i have found and i almost always use it is this:

http://blogs.microsoft.co.il/tomershamam/2007/10/30/wpf-localization-on-the-fly-language-selection/

give it a try. good luck

Upvotes: 1

Kashif
Kashif

Reputation: 3034

Due to cyclical dependency restrictions you cannot reference a control inside itself or its descendants in the tree. I would recommend you not to use converter for multilingual support. it is not a best way to do this. got here for best way to do. https://msdn.microsoft.com/en-us/library/ms745650(v=vs.110).aspx

Upvotes: 0

kennyzx
kennyzx

Reputation: 12993

You can pass the element name via the ConverterParameter property, this is an example of how it is used to pass a string to the converter.

However, WPF localization is more than returning different strings for different languages. You can read this article for more information and there is a Run Dialog Box example in the page to get you started.

Upvotes: 1

Related Questions