Skip to content

Localizing XAML Controls in Windows Projects

If you build desktop apps for Windows and wish to start using the new XAML-based controls via the DesktopXAMLContainer but aren’t sure how to localize those controls, here’s the solution:

  1. Drag a DesktopXAMLContainer to a window.
  2. Add the Opening event handler.
  3. In the Opening event handler, create the XAML string that defines the control you want and concatenate in your localized constant.

Here’s an example of a simple button with a localized constant named Hello used to define the button text:

Me.Content = "<Button Name='Button' Content='" + Hello + "' />"

Notice that you can use single quotes for the the values. Which makes concatenating them via code easier.

If you’re not exactly sure what the right XAML code is, drag out a DesktopXAMLContainer, click on the Pencil icon on it and then choose the control you want and click the OK button. In the Inspector, you can now edit the Content property of your control to see what the XAML code is to create that control. You can then set the Content property in the Opening event (as described above) using that string.

Geoff Perlman is the Founder and CEO of Xojo. When he’s not leading the Xojo team he can be found playing drums in Austin, Texas and spending time with his family.