1

I have a button that is enabled only when an item is selected in one of my list controls:

<Style TargetType="{x:Type Button}">                             
    <Style.Triggers>
        <DataTrigger Binding="{Binding SelectedIndex, ElementName=ganttChartTaskListView}" Value="-1">
            <Setter Property="IsEnabled" Value="False" />
        </DataTrigger>
    </Style.Triggers>
</Style>

I have to perform somewhat similar binding, however, in this new case I want to only have the button enabled when the SelectedIndex >= 1 (!= -1 && != 0)

How would I go about doing this in xaml?

1 Answer 1

3

Create an IValueConverter that returns True/False based on your condition. And change your Trigger to following:

<DataTrigger Binding="{Binding SelectedIndex, ElementName=ganttChartTaskListView, Converter={StaticResource MyConverter}}" Value="False">
    <Setter Property="IsEnabled" Value="False" />
</DataTrigger>
Sign up to request clarification or add additional context in comments.

1 Comment

Well, generally, I have not found a single converter/library that satisfies all my needs. I usually end up creating my own converters. But, you may want to look into this one : codeproject.com/KB/WPF/ScriptValueConverter.aspx?msg=2740680

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.