0

I would like to implement a multi binding for the header of my group box.

This is my current approach:

        <GroupBox>
            <GroupBox.Header>
                <TextBlock>
                    <TextBlock.Text>
                        <MultiBinding StringFormat="{}My Custom Header - {0}">
                            <Binding Path="VM.Obj1.Obj2.PropertyName"/>
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>
            </GroupBox.Header>
        </GroupBox>

If I implement it in this way, the header of my group box shows System.Windows.Controls.TextBlock

What is the correct way to use multi binding for the header of my group box so that the Text Block uses multi binding and binds to my strig property "PropertyName"? So the result shall be:

My Custom Header - StringValueOfPropertyName

1 Answer 1

3

You don't need a multibinding when there's only one binding:

<GroupBox>
    <GroupBox.Header>
        <TextBlock Text="{Binding VM.Obj1.Obj2.PropertyName, StringFormat=My Custom Header - {0}}"/>
    </GroupBox.Header>
</GroupBox>

In fact GroupBoxHeader allows string format directly using HeaderStringFormat:

<GroupBox Header="{Binding VM.Obj1.Obj2.PropertyName}"
          HeaderStringFormat="My Custom Header - {0}" />
3
  • I tried the HeaderStringFormat based on your example, it shows me the value of "PropertyName" but not the static part "My Custom Header -" in front of it.
    – ck84vi
    Commented Apr 7, 2020 at 10:33
  • If you override the header template like you've done, then HeaderStringFormat will be ignored. It only works if you bind the Header directly like my example. Commented Apr 7, 2020 at 10:39
  • Ok, I found the problem. In my actual code, I applied a style to the group box. And this style overrides the HeaderStringFormat. That's another problem now :-) . But your solution works. Have to figure out how to solve my style. Worst case I need a separate style, which I would like to avoid.
    – ck84vi
    Commented Apr 7, 2020 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.