Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to enable button if ListView has a selected item?

$
0
0

I have a ListView in my Xamarin.Forms project and I want to enable a button only if there is a selected item in the list view. I tried adding DataTrigger for my Button that checks for SelectedItem Value if it is null or not but this does not work

<StackLayout Orientation="Vertical">   
    <ListView x:Name="lvwCars" ItemsSource="{Binding Cars}"
      SelectedItem="{Binding SelectedCar}">
     <ListView.ItemTemplate>
      <DataTemplate>
       <ViewCell>
        <StackLayout Orientation="Horizontal">
         <Label Text="{Binding PlateNumber}" />
         <Label Text="{Binding OwnerName}" />    
        </StackLayout>
       </ViewCell>
      </DataTemplate>
     </ListView.ItemTemplate>
    </ListView>
</StackLayout>

<StackLayout Orientation="Horizontal"> 
    <Button x:Name="btnBack" 
            Text="Back" 
            Command="{Binding BackClickCommand}"/>
    <Button x:Name="btnNext" 
            Text="Next" 
            IsEnabled="False"
            Command="{Binding ConfirmClickCommand}">
     <Button.Triggers>
      <DataTrigger TargetType="Button" 
       Binding="{Binding Source={x:Reference lvwCars}, Path=SelectedItem}" Value="null">
       <Setter Property="IsEnabled" Value="False"/>
      </DataTrigger>
     </Button.Triggers>
    </Button>
</StackLayout>

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>