JoeB
JoeB

Reputation: 2815

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.

Upvotes: 5

Views: 3195

Answers (3)

Ricky
Ricky

Reputation: 103

when you disable the MenuItem in this code:

<MenuItem IsEnabled="False">
    <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>

the text doesn't become gray.

But if you make the same thing in this other code:

<MenuItem IsEnabled="False">
    <MenuItem.Header>
        <StackPanel Orientation="Horizontal">
            <Label Padding="0" Content="{x:Static properties:Resources.SEARCH_FOR_DAYS}" />
            <Label Padding="0" Content="{x:Static properties:Resources.ELLIPSES}" />
        </StackPanel>
    </MenuItem.Header>
</MenuItem>

Enable and disable works as expected on the color of the text

Upvotes: 0

Tim
Tim

Reputation: 15247

Off the top of my head, you might be able to do:

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

Upvotes: 4

Douglas
Douglas

Reputation: 54917

<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>    

Upvotes: 5

Related Questions