Reputation: 179
I wanna make my Button's IsEnabled property to check if ListView has a selection. Is there any way to check if any ListView item is selected using only XAML? Something like:
<Button Content="Remove" Command="{Binding RemoveConditionCommand}"
CommandParameter="{Binding ElementName=conditionsListView, Path=SelectedItem}"
IsEnabled="{Binding ElementName=conditionsListView, Path=IsSelected}"
/>
Upvotes: 2
Views: 1189
Reputation: 81243
You can achieve that using DataTrigger
. Set IsEnabled to false in case selectedItem is null for ListView.
Sample:
<Button>
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=SelectedItem,
ElementName=conditionsListView}"
Value="{x:Null}">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
Upvotes: 3