Search code examples
c#wpfdata-bindingmultibindingmarkup-extensions

'System.Windows.Data.MultiBinding' is not a valid value for property 'Text'


I'm trying to write a custom MarkupExtension that allows me to use my own mechanisms for defining a binding, however when I attempt to return a MultiBinding from my MarkupExtension I get the above exception.

I have:

<TextBlock Text="{my:CustomMarkup ...}" />

CustomMarkup returns a MultiBinding, but apparently Text doesn't like being set to a MultiBinding. How come it works when I say:

<TextBlock>
    <TextBlock.Text>
        <MultiBinding ... />
    </TextBlock.Text>
</TextBlock>

But it doesn't work the way I'm doing it?


Solution

  • Don't return the MultiBinding itself. Instead, return the result of MultiBinding.ProvideValue.

    BTW, what exactly are you doing in your markup extension ? Perhaps you could just inherit from MultiBinding, if you don't need to override ProvideValue (which is sealed). You can achieve almost anything by just setting the appropriate Converter and other properties