XAML C# Localization problems
NickName:Eric after dark Ask DateTime:2013-07-03T23:29:28

XAML C# Localization problems

Okay, so the overall goal of this prototype is to create a GUI window using WPF in C# that allows the user to change languages from a menu. At the moment I am trying to switch some of the components of my window from English to German using an App.config file. I know that will not allow the assets to change using a button, but it's a start.

I have 3 resource files. One is a default (English), another is English as well, labelled en-US, and the last one is German, labelled de-DE. They are all PUBLIC.

I have used these two videos as guide lines:

http://www.youtube.com/watch?v=5MuN6VOw9r4

http://www.youtube.com/watch?v=BK7jp3snwCQ

I set the content of a label and two buttons in the XAML section:

<Label Content="{x:Static properties:Resources.Label1}" Height="28" Margin="6,6,79,0" Name="Label1" VerticalAlignment="Top"></Label>
<Button Content="{x:Static properties:Resources.Button1}" Height="23" HorizontalAlignment="Left" Margin="6,40,0,0" Name="Button1" VerticalAlignment="Top" Width="75"></Button>
<Button Content="{x:Static properties:Resources.Button2}" Height="23" HorizontalAlignment="Left" Margin="6,69,0,0" Name="Button2" VerticalAlignment="Top" Width="75"></Button>

This is what I have in my App.config file (de-DE) should change the edited content to German:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="Culture" value="de-DE" />
  </appSettings>
</configuration>

Lastly, my xaml.cs file has the following in it:

using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Globalization;
using System.Configuration;

namespace WPF_Prototype1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            /// This line should allow the program to read the App.config file!
            Properties.Resources.Culture = new CultureInfo(ConfigurationManager.AppSettings["Culture"]);
        }
    }
}

Why is my program still not changing these icons to German? What can I do to fix it?

Thank you

Copyright Notice:Content Author:「Eric after dark」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/17452094/xaml-c-sharp-localization-problems

Answers
Eric after dark 2013-07-03T19:42:20

The first thing that i did to fix my problem was to create a new project. Under the new project I created the same 3 Resource files and added them to the project properties. After that I created the same App.config file.\n\n<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<configuration>\n <appSettings>\n <add key=\"Culture\" value=\"de-DE\" />\n </appSettings>\n</configuration>\n\n\nI also left the same code in the xaml.cs file:\n\nProperties.Resources.Culture = new CultureInfo(ConfigurationManager.AppSettings[\"Culture\"]);\n\n\nAfter making sure that all of the names were matching in my resource files I wrote out the following code in the xaml design window:\n\n<Label Content=\"{x:Static properties:Resources.LabelFirstName}\" Height=\"28\" HorizontalAlignment=\"Left\" Margin=\"33,29,0,0\" Name=\"labelFName\" VerticalAlignment=\"Top\" />\n <Label Content=\"{x:Static properties:Resources.LabelLastName}\" Height=\"28\" HorizontalAlignment=\"Left\" Margin=\"34,65,0,0\" Name=\"labelLName\" VerticalAlignment=\"Top\" />\n <Label Content=\"{x:Static properties:Resources.LabelAddress}\" Height=\"28\" HorizontalAlignment=\"Left\" Margin=\"35,103,0,0\" Name=\"labelAddress\" VerticalAlignment=\"Top\" />\n <TextBox Height=\"23\" HorizontalAlignment=\"Left\" Margin=\"119,26,0,0\" Name=\"textBoxFName\" VerticalAlignment=\"Top\" Width=\"152\" />\n <TextBox Height=\"23\" HorizontalAlignment=\"Left\" Margin=\"119,63,0,0\" Name=\"textBoxLName\" VerticalAlignment=\"Top\" Width=\"152\" />\n <TextBox Height=\"23\" HorizontalAlignment=\"Left\" Margin=\"119,100,0,0\" Name=\"textBoxAddress\" VerticalAlignment=\"Top\" Width=\"152\" />\n <Button Content=\"{x:Static properties:Resources.EnglishButton}\" Height=\"23\" HorizontalAlignment=\"Left\" Margin=\"177,155,0,0\" Name=\"englishButton\" VerticalAlignment=\"Top\" Width=\"94\" />\n <Button Content=\"{x:Static properties:Resources.GermanButton}\" Height=\"23\" HorizontalAlignment=\"Left\" Margin=\"177,207,0,0\" Name=\"germanButton\" VerticalAlignment=\"Top\" Width=\"94\" />\n\n\nI think the difference was the name of the asset from the resource file being DIFFERENT from the name in the xaml design window. For example, my first lable is called \"LabelFirstName\" in the resource files, but it's called labelFName in the xaml window. I also didn't drag and drop any of the components. I made sure that they were in written format.",


More about “XAML C# Localization problems” related questions

wpf xaml to c# TargetProperty

I need to convert xaml code to c# I have two animation xaml code, first fade in animation : in xaml : Storyboard.TargetProperty="(UIElement.Opacity)" in c# : Storyboard.SetTargetProperty(

Show Detail

XAML to C# conversion tool

Is there a XAML to C# conversion tool? I have a control template defined in XAML, but I want to create this template and it's styles using C#, so I can obfuscate the code version (since I can't obf...

Show Detail

C# to Xaml Conversion

I want to implement a custom accordion ui element but the code has been written in C# ( https://github.com/Kimserey/AccordionView ) but I want to use xaml. I tried to add Accordion view in my conte...

Show Detail

Direct Coding XAML in C# (WPF)

Is there a way to directly write XAML code for a bound variable in C#? What I mean by this is, if I have an XAML object databound to a C# variable, would I be able to directly write XAML code for t...

Show Detail

Why XAML is compiled into BAML and not in C#

As far as I know, everything done in XAML can be done in C#. Why XAML is compiled in BAML and not in C# ? Wouldn't be more efficient to parse the XAML at compile-time and create the corresponding...

Show Detail

Why XAML is compiled into BAML and not in C#

As far as I know, everything done in XAML can be done in C#. Why XAML is compiled in BAML and not in C# ? Wouldn't be more efficient to parse the XAML at compile-time and create the corresponding...

Show Detail

In C# XAML Windows 8 Application Is It Possible Not to Use XAML

I have come across with something on one of my colleague's code who is recently coding for a Win 8 Metro Style App(C# XAML) as me. The point that made me curious is that he did not use any XAML code(

Show Detail

WPF Data Binding TooWay XAML to C# and C# to XAML

I have XAML code: &lt;TextBox Name="textBoxMask1"/&gt; &lt;TextBox Name="textBoxMask2"/&gt; &lt;TextBox Name="textBoxMask3"/&gt; ... &lt;TextBox Name="textBoxMask9&quo

Show Detail

Converting XAML ObjectDataProvider to C#

I would like to create my ObjectDataProvider in my C# code behind rather than my XAML. I was wondering how to change this XAML into equivalent C#. The XAML was generated by Microsoft Expression Bl...

Show Detail

How to turn XAML to pure C#?

How to turn XAML to pure C# (xaml was made for c# app )?

Show Detail