Search code examples
wpfxamllocalizationresources

Append WPF resource strings


I want to append two static strings for a single content or header of a WPF object. Something like this:

<MenuItem 
    Header="{x:Static properties:Resources.SEARCH_FOR_DAYS} + 
            {x:Static properties:Resources.ELLIPSES}" /> 

I've played around with ContentStringFormat and the like but can't get it to accept two resources.


Solution

  • <MenuItem>
        <MenuItem.Header>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{x:Static properties:Resources.SEARCH_FOR_DAYS}" />
                <TextBlock Text="{x:Static properties:Resources.ELLIPSES}" />
            </StackPanel>
        </MenuItem.Header>
    </MenuItem>
    

    Alternatively (closer to what you requested):

    <MenuItem>
        <MenuItem.Header>
            <MultiBinding StringFormat="{}{0}{1}">
                <Binding Path="{x:Static properties:Resources.SEARCH_FOR_DAYS}"/>
                <Binding Path="{x:Static properties:Resources.ELLIPSES}"/>
            </MultiBinding>
        </MenuItem.Header>
    </MenuItem>