Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView item stays selected after returning to page

I am on the most current version of Xamarin Forms. I have a Content Page. The Content Page has a content that has a ListView that has a ItemTemplate that contains some ImageCell. When I touch one list element I use Tapped_Event which navigate to other page. When I go back this page the ImageCell tapped color stay with Orange. I dont want to stayed with this Orange color. Anybody can help me?

This is my XAML code:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Spirocco.MedicationPage"
         Title="Gyógyszerek">
<ContentPage.Content>
    <ListView x:Name="Medications" ItemsSource="{Binding Medications}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ImageCell ImageSource="{Binding Icon}" Text="{Binding Name}" Detail="{Binding Type}" Tapped="ImageCell_Tapped" />
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage.Content>

ImageCell_Tapped method:

private async void ImageCell_Tapped(object sender, EventArgs e)
    {
        await Navigation.PushAsync(new MedicationDetailPage((Medication)Medications.SelectedItem));
    }
like image 431
Tamás Deák Avatar asked Dec 16 '17 11:12

Tamás Deák


1 Answers

"Deselected" the SelectedItem after your PushAsync:

private async void ImageCell_Tapped(object sender, EventArgs e)
{
    await Navigation.PushAsync(new MedicationDetailPage((Medication)Medications.SelectedItem));

    // Manually deselect item
    Medications.SelectedItem = null;
}
like image 71
SushiHangover Avatar answered Oct 11 '22 08:10

SushiHangover