views:

303

answers:

1

I want to bind a buttons IsEnabled property to (myObject.SelectedIndex >= 0).... isn't there a simple way to do this in the xaml (without having to do crazy things to any underlying objects)? I haven't really seen a good example.

Honestly, I wish this was as easy as Flex 3 ... I.E.:

<mx:Button enabled="{dataGrid.SelectedIndex >= 0}" ...
+3  A: 

SelectedIndex is -1 if nothing's selected, right? Reverse your logic and use a trigger:

<mx:Button ...>
    <mx:Button.Style>
        <Style TargetType="{x:Type mx:Button}">
            <Setter Property="enabled" Value="True" />

            <Style.Triggers>
                <DataTrigger
                    Binding="{Binding SelectedIndex,ElementName=dataGrid}"
                    Value="-1">

                    <Setter Property="enabled" Value="False" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </mx:Button.Style>
</mx:Button>
Matt Hamilton
Thanks, I can use that for one of my buttons, but the other one would be where SelectedIndex >= 1. Can I do that like your sample above but just with a MultiDataTrigger?
Chris Klepeis
MultiDataTrigger is used when the conditions are anded together. To do SelectedIndex>=1 copy the datatrigger for '-1' and change the trigger value to '0'.
Cameron MacFarland