I have following code. Here listClear is an object, which is filled by ViewModel. I am using properties of this object to fill a Grid. In below code what property should I use to make Button disable in DataTrigger. I want Button to be disabled when Grid is empty, otherwise it should be enabled.
<Button Grid.Column="3" Margin="2" Command="{Binding Path=ClearCommand}" Content="Clear">
<Button.Style>
<Style TargetType="Button">
<Setter Property="IsEnabled" Value="True" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=listClear}" Value="">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
You can use the
ListCountproperty for this to indicate emptyExample:
Xaml:
If your only using
IEnumerable<T>its a bit more difficult becauseIEnumerablehas no public properties to bint to, you would have to make a converter.Something like this
Xaml: