Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding at Design-Time to WPF Labels, Buttons, etc?

Tags:

vb.net

mvvm

wpf

We're developing a WPF & MVVM application that requires multi-language support. On each control with static text, we're using a converter to do a lookup for the appropriate word for the user's language.

However, this means that each control does not display any text. This causes some irritation for the UI developers at design-time. Is there any way to display design-time text?

For example:

        <TextBlock>
          <TextBlock.Text>
              <Binding Converter="{StaticResource Translator}"
                       Path="Controller"
                       ConverterParameter="Search for" />
          </TextBlock.Text>
        </TextBlock>

How can I make this converter execute at design time to display the translated converter parameter?

like image 626
Daniel Avatar asked Dec 06 '25 13:12

Daniel


1 Answers

First of all I would suggest that you use a markup extension for that. Then you markup would look something like this:

<TextBlock Text="{my:Localize Key=MyLabel, Default='The text you want to be displayed by default'}" .../>

The default text will also be displayed in Blend.

Second of all I don't see the problems with the converter approach as long as the converter returns a valid default text. In other words converters should be executed in design time as well as in run time.

like image 175
Pavlo Glazkov Avatar answered Dec 09 '25 04:12

Pavlo Glazkov