Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Is it possible to set an items visibility depending if list view item is selected

JKayJKay USMember ✭✭✭
edited October 2015 in Xamarin.Forms

I have a listview like so:

 <ListView x:Name="listView" ItemsSource="{Binding Customers}" SelectedItem="{Binding SelectedCustomer}">

                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="30"/>

                          <StackLayout Grid.Column="0">
                            <Label Text="{Binding Name}"  FontAttributes="Bold"/>
                            <Label Text="{Binding Address, Converter={StaticResource AddressToStringConverter}, ConverterParameter={StaticResource SortAdressLength}}" />
                            <Image Grid.Column="1" Source="Info.png"/> <!-- Visibility depending on if selected -->

Now I would like to set the Image "Info.png" to only be visible on whether the ListViewItem is selected. Now in WPF I would add a ListViewItemContainerStyle with a Trigger dependent on whether the ListViewItem was selected and set the Visibility.

I also know that I could have a property on my customer object called IsSelected and use that. But maintaining a property called IsSelected Seems very scrappy to me?

Is there a better way?

In addition to this I would also like to set my Selected Item background using a similar technique


  • AdamMeaneyAdamMeaney USMember ✭✭✭✭✭

    Xamarin Forms has Triggers and Behaviors. One of those will do what you want, I can just never remember which does what.

  • Quan.HoangQuan.Hoang USMember ✭✭

    I would set the IsVisible to true or false accordingly on the listview ItemSelected

Sign In or Register to comment.