views:

60

answers:

1

I have this application that has dynamic language switching built in. Based on the selected Culture, strings throughout the application will change. Translated strings and their original values come out of resource files. I use bindings to attach the resource values to buttons, labels, etc. Most of this binding occurs in the code behind.

I've been able to concatenate localized strings with data using the Binding.StringFormat property:

mybinding.StringFormat = "# {0}";

for "# of items". My problem is that I now need to concatenate two (or more) localized strings in the code behind. I quickly realized I could use MultiBinding and add my bindings to it, keeping with how things currently work, however, using MultiBinding.StringFormat doesn't seem to work. I'm trying to use myMultiBinding.StringFormat = "{0} {1}"; to insert a space between the two binding values, but it just appears blank when bound to the "Greetings" Label.

Binding b = GetBinding("HelloWorld");   
Binding b2 = GetBinding("Name");

MultiBinding multib = new MultiBinding();
multib.StringFormat = "{0} {1}";
multib.Bindings.Add(b);
multib.Bindings.Add(b2);
Greetings.SetBinding(Label.ContentProperty, multib);

and here's the GetBinding() function which grabs a binding based on the path value:

public Binding GetBinding(string name)
{
    Binding binding = new Binding();
    binding.Source = mySource;
    binding.Path = new PropertyPath(name);
    return binding;
}

Also, I should note I'm using .NET 4. Doesn't seem to work in Xaml either. I have also tried this in .NET 3.5 after it didn't work in 4.0. Both child bindings are working... if I supply a converter, the values show up. I'd rather use the StringFormat property though.

A: 

It's a problem with the Label. StringFormat on TextBlock seems to work...

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/69bca541-379f-4f8d-ab19-2f55b566e2c9/#1c06f05e-631c-4e51-95f4-cac83a3f457b

sub-jp