-3

I work on a Multi-Language application, everything is ok except the binding values, ex: In my user group table I have two fields name and en_name, I bind the name to a Textbox:

<TextBox Text="{Binding name}"/>

When I change the language of my application, How can I change the binding to en_name?

newbie
  • 51
  • 1
  • 1
  • 7
Abdulsalam Elsharif
  • 4,773
  • 7
  • 32
  • 66
  • I don't that is a scalable approach for writing a multilingual application, what happens when you need an additional language ? you'll need to add more properties. It's better to create a resx file for your strings, and create a different one for each language. – Athul Raj Nov 05 '20 at 09:54
  • I think @Athul is correct. You should not create different variables for the language but you should update the `name` variable when changing a language and binging will update it in UI – Sergey Anisimov Nov 05 '20 at 10:04
  • Don't invent a wheel, look e.g. [here](https://www.wpftutorial.net/LocalizeMarkupExtension.html) for markup extension solution. – Sinatr Nov 05 '20 at 10:13
  • See also https://stackoverflow.com/questions/4041197/how-to-set-and-change-the-culture-in-wpf and the discussion of localization at https://stackoverflow.com/questions/1916510/are-windows-forms-old-tech – Peter Duniho Nov 05 '20 at 19:25

2 Answers2

1

When I change the language of my application, How can I change the binding to en_name?

You don't. You change the value of the name source property to return the English name.

If you want to change the actual binding, you need to do this yourself programmatically:

textBox.SetBinding(TextBox.TextProperty, new Binding("en_name"));
mm8
  • 163,881
  • 10
  • 57
  • 88
0

Hello @Abdulsalam Elsharif,

this is the wrong approach ideally but if this is your requirement then I would suggest passing the current language and rename the column.

SELECT en_name as [name] from table;

Ravi vanzara
  • 73
  • 1
  • 7