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

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

$
0
0

I have a listview like so:

 <ListView x:Name="listView" ItemsSource="{Binding Customers}" SelectedItem="{Binding SelectedCustomer}">
                <ListView.ItemTemplate>
                  <DataTemplate>
                    <ViewCell>
                      <ViewCell.View>
                        <Grid>

                          <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="30"/>
                          </Grid.ColumnDefinitions>

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

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


Viewing all articles
Browse latest Browse all 75885

Trending Articles



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