Search code examples
c#wpfxamlmultibindingsyncfusion

WPF MultiBinding fails in Syncfusion TabItemExt header


I have a subclass of TabItem as follows, for which I'm trying to set the Header property. I've tried this with a MultiBinding:

<DataEditPane x:TypeArguments="MyType" x:Class="MyDataEditPane">
    <DataEditPane.Header>
        <MultiBinding StringFormat="Hello world {0} {1}">
            <Binding Path="BoundVariable1" />
            <Binding Path="BoundVariable2" />
        </MultiBinding>    
    </DataEditPane.Header>
</DataEditPane>

But it fails as such:

System.Windows.Data Error: 28 : MultiBinding failed because it has no valid Converter. MultiBindingExpression:target element is 'MyDataEditPane' (Name=''); target property is 'Header' (type 'Object')
System.Windows.Data Error: 28 : MultiBinding failed because it has no valid Converter. MultiBindingExpression:target element is 'MyDataEditPane' (Name=''); target property is 'Header' (type 'Object')

I'd always thought the StringFormat served the role of the converter, but perhaps not?

Wrapping the fields together in some kind of container, like a Label, also doesn't seem to work:

<DataEditPane x:TypeArguments="MyType" x:Class="MyDataEditPane">
    <DataEditPane.Header>
        <Label>
            <Label.Text>
                <MultiBinding StringFormat="Hello world {0} {1}">
                    <Binding Path="BoundVariable1" />
                    <Binding Path="BoundVariable2" />
                </MultiBinding>    
            </Label.Text>
        </Label>
    </DataEditPane.Header>
</DataEditPane>

In this case, the .ToString() representation of the label ("System.Windows.Controls.Label") is shown as the header.

Note that a single binding works just fine:

<DataEditPane x:TypeArguments="MyType" x:Class="MyDataEditPane">
    <DataEditPane.Header>
        <Binding Path="BoundVariable1" />
    </DataEditPane.Header>
</DataEditPane>

If it matters, I'm using the Syncfusion TabItemExt as one of my superclasses in the inheritance hierarchy, but as that class doesn't override the Header property I don't think that makes a difference.

What am I doing wrong? I know I can make another property in the ViewModel to act as the Header (and then single-bind that) but I want to learn how to do this properly in XAML.


Solution

  • Multi-Bindings requires a converter, i think that a converter that you may use is the StringFormatConverter, it is a IMultiValueConverter so works for multibindings. Maybe you should adapt it to your case.

    Hope this could be useful for you...