Search code examples
c#wpfmvvmdesktop-applicationdynamicresource

WPF : How to bind a string to Dynamic resource for a label content


I am new to WPf and MVVM. I have Dynamic language change functionality in my wpf application. For this functionality I have 2 Resource dictionary for each language.On Language change in UI, I am adding and removing the corresponding ResourceDictionary to the application. With this, at a given point of time only one Resource Dictionary is available in Application resource.

As all strings are Dynamic resource, I need to now how to add a string to a dynamic resource string in xaml.

For ex: I want something like below

 <Label FontWeight="Medium" Content="{DynamicResouce Name} + myText"/>

Here "Name" is a Key available in both resource dictionary as shown below.

<system:String x:Key="Name">Name</system:String>

Now, need to know how to attach "myText" to the Name(DynamicResource) in the Label Content.


Solution

  • You can just simply use TextBlock inside the Label

    <Label>
       <TextBlock>
          <Run Text="Text1"/>
          <Run Text="Text2"/>
       </TextBlock>
    </Label>