Search code examples
c#wpfxamlmvvm

How to bind WPF window title to a viewmodel property and to a static resource property?


In my WPF application, I have a window whose title is a 2 word string. First word, i need to bind to a ViewModel property and second word, I need to get from resource file as i need to apply localization to that word.

I am not sure how to bind these two different things in the window title. I want something like the below one.

<Window Title= "Viewmodel Property + static resource property">
</Window>

Solution

  • You can set a MultiBinding like that.

    <Window ...>
       <Window.Title>
          <MultiBinding StringFormat=" {0} {1}">
             <Binding Path="ViewModelProperty"/>
             <Binding Source="{x:Static local:YourStaticProperty}"/>
          </MultiBinding>
       </Window.Title>
       ...
    </Window>