user3033043
user3033043

Reputation:

Enable button only if two ListViews have at least 1 item (via WPF Triggers)

I want to enable/disable a button depending on the count of items within 2 ListView controls.

Both ListViews must have at least 1 item (each) before the button control is being enabled.

So far, all I found was a way for one ListView without triggers:

// ToDo: ListViewTwo must be included
<Button IsEnabled="{Binding ElementName=ListViewOne, Path=Items.Count}" />

Is there any way to consider ListViewToo, too?

Upvotes: 0

Views: 733

Answers (1)

mm8
mm8

Reputation: 169420

You should be able to use a Style with two DataTriggers:

<Button>
    <Button.Style>
        <Style TargetType="Button">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Items.Count, ElementName=listViewOne}" Value="0">
                    <Setter Property="IsEnabled" Value="False" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Items.Count, ElementName=listViewTwo}" Value="0">
                    <Setter Property="IsEnabled" Value="False" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>

Upvotes: 1

Related Questions