Search code examples
wpfbuttonbindingmultibindingisenabled

why can't I use multibinding with the IsEnabled property of the button?


I am trying to set the IsEnabled property of a button using multibinding, because this property depends on three variables.

If I would set the content propery, I could use this code:

<Button Height="23" HorizontalAlignment="Left" Margin="629,49,0,0" Name="btnMyButton" VerticalAlignment="Top" Width="75">
                    <Button.Content>
                        <MultiBinding Converter="{StaticResource myMultiValueConverter}">
                            <Binding ElementName="MyElement"/>
                            <Binding />
                        </MultiBinding>
                    </Button.Content>
</Button>

I try to use this code:

<Button Height="23" HorizontalAlignment="Left" Margin="629,49,0,0" Name="btnMyButton" VerticalAlignment="Top" Width="75">
                    <Button.IsEnabled>
                       <?????

But in this case, although the Button.IsEnabled is avaliable, in the next line I can't find the Multibinding keyword, so I can't use multibinding with the IsEnabled property.

why? Is there any way to set the IsEnabled property with a multivalue converter?

Thanks.


Solution

  • The syntax should be the exact same as what you have for Button.Content - just replace "Content" with "IsEnabled".

    <Button.IsEnabled>
        <MultiBinding Converter="{StaticResource myMultiValueConverter}">
            <Binding ... />
            <Binding ... />
            <Binding ... />
        </MultiBinding>
    </Button.IsEnabled>
    

    It might not auto-complete for you because the IsEnabled property expects a boolean value, not a MultiBinding object, but it shouldn't give you any errors, and will compile and execute just fine.

    (It auto-completes for Button.Content because the Content property is of type object, which includes a MultiBinding object)