Refresh text put in code behind

Mar 7, 2013 at 2:37 PM
Hi,

Thanks for your extension !

Just one thing, I put text in code behind :
TextBlock tb = new TextBlock();
 tb.Text = GetUIString("myKey");

public string GetUIString(string key)
        {
            string uiString;
            LocExtension locExtension = new LocExtension("myAsselbly:I18n:" + key);
            locExtension.ResolveLocalizedValue(out uiString);
            return uiString;
        }
When I change the language all my string put in XAML are updated but not the others...

Thanks for your help!
Coordinator
Mar 8, 2013 at 10:20 AM
Hi,

Here we have a code example how to do code behind binding.

So instead setting the value your self you establish the binding to the textbox.
I hope that helps.

Cheers
Mar 14, 2013 at 1:13 PM
That was it!
Coordinator
Mar 15, 2013 at 8:17 AM
You're welcome!
Aug 31, 2013 at 12:35 PM
Hi

I have a problem of the same kind. I try to use WPF Localize Extension with Modern UI for WPF ( http://mui.codeplex.com ).

SeriousM : can this solution be used with property that are not dependencyProperty ? I tried to give the property I want to localize as second argument for the method SetBinging but it doesn't seems to work
var loc = new LocExtension("ChefOrchestre:Strings:SettingsView_Link_General");
bool success = loc.SetBinding(LinkGeneral, LinkGeneral.DisplayName);
The error I get
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at XAMLMarkupExtensions.Base.NestedMarkupExtension.SetPropertyValue(Object value, TargetInfo info, Boolean forceNull)
   at WPFLocalizeExtension.Extensions.LocExtension.SetBinding(Object targetObject, Object targetProperty, Int32 targetPropertyIndex)
   at WPFLocalizeExtension.Extensions.LocExtension.SetBinding(Object targetObject, Object targetProperty)
   at ChefOrchestre.View.SettingsView..ctor() in c:\Users\Julien\Documents\Visual Studio 2012\Projects\ChefOrchestre\ChefOrchestre\View\SettingsView.xaml.cs:line 20
Julien
Coordinator
Sep 1, 2013 at 9:18 PM
Hi Julien,

the second parameter must be of type "DependencyProperty" or "PropertyInfo". The latter would fit to your task. You can retrieve it using reflection on the type of "LinkGeneral".

Best regards,
Uwe
Sep 2, 2013 at 6:21 PM
Thank you, it works.

And is there a solution to do that in the XAML code and not code behind ? In fact that was my initial problem, I have done like in the documentation and that didn't work with the property that are not DependencyProperty.


Julien
Coordinator
Sep 25, 2013 at 9:49 PM
Hi Julien,

Sorry, this won't work due to the restrictions of markup extensions.

Best regards,
Uwe