0

Hi I am trying to achieve a binding like this:

<ComboBoxItem Style="{StaticResource ComboBoxItemStyle2}">
    <ComboBoxItem.Content>
        <MultiBinding StringFormat=" {}{0} {1}">
            <Binding Path="Value" Source="{StaticResource Name}" />
            <Binding Path="Name" Source="{StaticResource Person}" />
        </MultiBinding>
    </ComboBoxItem.Content>
</ComboBoxItem>

Where "Name" is a localized string and "Value" is used to get it's localized string. for some reason this doesn't seems to work. I am getting empty string.

nishantcop
  • 977
  • 1
  • 8
  • 24

3 Answers3

1

This might help you: String format using MultiBinding?

Taken from that post:

You are trying to bind a string to an object. But StringFormat requires its target to be a string type. Try putting a TextBlock in your content and bind your data to it.

Also put "" around Name.

Community
  • 1
  • 1
user1182735
  • 764
  • 9
  • 21
1

Following is the corrected code:

<ComboBoxItem Style="{StaticResource ComboBoxItemStyle2}">
    <TextBlock>
        <TextBlock.Text>
            <MultiBinding StringFormat="{}{0} {1}">
                <Binding Path="Value" Source="{StaticResource Name}" />
                <Binding Path="Name" Source="{StaticResource Person}" />
            </MultiBinding>
        </TextBlock.Text>
    </TextBlock>
</ComboBoxItem>

I need to fix two things:

  1. Keep the content as TextBlock and do binding of text there.
  2. Removed extra spacing from StringFormat i.e. " {}{0} {1}" ==> "{}{0} {1}".
nishantcop
  • 977
  • 1
  • 8
  • 24