title: Xamarin Forms UWP listview does not work when page is created for a second time
body: <p>I am working on a Xamarin Forms UWP application and I have a page that loads a listview of Opportunities (My own model). The listview works fine when I try and access it for the first time. I can click on an item in the listview and it loads another page containing more details pertaining to that particular opportunity item in the listview. I can then click the back button and navigate to the page containing the listview and then select another item and navigate to the page that displays more details pertaining to that particular opportunity item.</p>
  
  <p>The problem comes when I click on a totally different page and then try to navigate back to the page that loads the Opportunities listview. The listview will load correctly but when I try clicking on one of the items, it does not navigate to the page that would display more details pertaining to that item, meaning that the itemtapped/ItemSelected is not firing again for some reason.</p>
  
  <p>I am using PRISM and I also made use of Prism's Event to Command Behavior. I then switched and ended up creating my own event to command behavior and set the Listview.SelectedItem to null in the OnDetachingFrom() method but I am still seeing the same results.</p>
  
  <p>I have also tried setting the SelectedItem to null in the code behind. Still did not work.</p>
  
  <p>In the Android version, everything works well. What could be the issue here?
  Any help is highly appreciated. I am a beginner and this is my first Forms app.</p>
  
  <pre><code>&lt;!--My OpportunitiesPage View--&gt;
  &lt;ScrollView&gt;
          &lt;ListView x:Name="OpportunitiesList" CachingStrategy="RecycleElement" BackgroundColor="Transparent" RowHeight="200" ItemsSource="{Binding OpportunitiesList, Mode=TwoWay}" SeparatorVisibility="None" SelectedItem="{Binding SelectedOpportunity, Mode=TwoWay}"&gt;
              &lt;ListView.Behaviors&gt;
                  &lt;Local:ItemSelectedToCommandBehaviour Command="{Binding SelectOpportunityCommand}"/&gt;
              &lt;/ListView.Behaviors&gt;
              &lt;!--ViewCell stuff goes here--&gt;
          &lt;/ListView&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <pre class="lang-cs prettyprint-override"><code>//My ViewModel for the Opportunities Page
      public class OpportunitiesPageViewModel : BindableBase, INavigationAware
      {
          INavigationService _navigationService;
  
          private DelegateCommand&lt;Opportunities&gt; _selectedOpportunityCommand;
          public DelegateCommand&lt;Opportunities&gt; SelectedOpportunityCommand =&gt; _selectedOpportunityCommand ?? (_selectedOpportunityCommand = new DelegateCommand&lt;Opportunities&gt;(async (EventArgs)=&gt; await ShowOpportunityDetails(EventArgs)));
  
          public ICommand SelectOpportunityCommand { get; private set; }
  
          private Opportunities _selectedOpportunity;
          public Opportunities SelectedOpportunity { get { return _selectedOpportunity; } set =&gt; SetProperty(ref _selectedOpportunity, value); }
  
          IList&lt;Opportunities&gt; _listCopy;
          public IList&lt;Opportunities&gt; ListCopy { get { return _listCopy; } set =&gt; SetProperty(ref _listCopy, value); }
  
          IList&lt;Opportunities&gt; _opportunitiesList;
          public IList&lt;Opportunities&gt; OpportunitiesList { get { return _opportunitiesList; } set =&gt; SetProperty(ref _opportunitiesList, value); }
  
          Opportunities _opportunity1;
          Opportunities _opportunity2;
          Opportunities _opportunity3;
          Opportunities _opportunity4;
          Opportunities _opportunity5;
  
          public Opportunities Opportunity1 { get { return _opportunity1; } set =&gt; SetProperty(ref _opportunity1, value); }
          public Opportunities Opportunity2 { get { return _opportunity2; } set =&gt; SetProperty(ref _opportunity2, value); }
          public Opportunities Opportunity3 { get { return _opportunity3; } set =&gt; SetProperty(ref _opportunity3, value); }
          public Opportunities Opportunity4 { get { return _opportunity4; } set =&gt; SetProperty(ref _opportunity4, value); }
          public Opportunities Opportunity5 { get { return _opportunity5; } set =&gt; SetProperty(ref _opportunity5, value); }
  
          public OpportunitiesPageViewModel(INavigationService navigationService)
          {
              _navigationService = navigationService;
  
              OpportunitiesList = new ObservableCollection&lt;Opportunities&gt;
              {
                  new Opportunities
                  {
                      Id = 0,
                  HeaderImage = "https://images.unsplash.com/photo-1462899006636-339e08d1844e?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=1350&amp;q=80",
                  Author = "Justin Pillay",
                  DatePublished = DateTime.Now.ToShortDateString(),
                  Title = "Funding for SMMEs",
                  Body = "Lorem ipsum dolor sit amet,consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                  Category= "Funding",
                  Organisation = "Yobuningi (Pty) Ltd",
                  ContactWebsite = "www.yobuningi.co.za",
                  ContactEmail = "info@yobuningi.co.za",
                  ContactNumber1 = "0111234567",
                  ContactNumber2 = "0111234567",
                  ContactPerson = null
                  },
  
                  new Opportunities
                  {
                      Id = 0,
                  HeaderImage = "https://images.unsplash.com/photo-1444653614773-995cb1ef9efa?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=1355&amp;q=80",
                  Author = "Justin Pillay",
                  DatePublished = DateTime.Now.ToShortDateString(),
                  Title = "Growth for SMMEs",
                  Body = "Lorem ipsum dolor sit amet,consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                  Category = "Business Support",
                  Organisation = "Yobuningi (Pty) Ltd",
                  ContactWebsite = "www.yobuningi.co.za",
                  ContactEmail = "info@yobuningi.co.za",
                  ContactNumber1 = "0111234567",
                  ContactNumber2 = "0111234567",
                  ContactPerson = null
                  },
  
                  new Opportunities
                  {
                       Id = 0,
                  HeaderImage = "https://images.unsplash.com/photo-1507679799987-c73779587ccf?ixlib=rb-1.2.1&amp;auto=format&amp;fit=crop&amp;w=1351&amp;q=80",
                  Author = "Justin Pillay",
                  DatePublished = DateTime.Now.ToShortDateString(),
                  Title = "Business Support for SMMEs",
                  Body = "Lorem ipsum dolor sit amet,consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                  Category = "Business Support",
                  Organisation = "Yobuningi (Pty) Ltd",
                  ContactWebsite = "www.yobuningi.co.za",
                  ContactEmail = "info@yobuningi.co.za",
                  ContactNumber1 = "0111234567",
                  ContactNumber2 = "0111234567",
                  ContactPerson = null
                  },
  
                  new Opportunities
                  {
                      Id = 0,
                  HeaderImage = "https://images.unsplash.com/photo-1517245386807-bb43f82c33c4?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=1350&amp;q=80",
                  Author = "Justin Pillay",
                  DatePublished = DateTime.Now.ToString(),
                  Title = "New Incubation Hub to open in Johannesburg",
                  Body = "Lorem ipsum dolor sit amet,consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                  Category = "Business Support",
                  Organisation = "Yobuningi (Pty) Ltd",
                  ContactWebsite = "www.yobuningi.co.za",
                  ContactEmail = "info@yobuningi.co.za",
                  ContactNumber1 = "0111234567",
                  ContactNumber2 = "0111234567",
                  ContactPerson = null
                  },
  
                  new Opportunities
                  {
                       Id = 0,
                  HeaderImage = "https://images.unsplash.com/photo-1545239249-27f6fa8b6b4a?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=600&amp;q=60",
                  Author = "Justin Pillay",
                  DatePublished = DateTime.Now.ToShortDateString(),
                  Title = "Aunty Sameema gonna soot you!",
                  Body = "Lorem ipsum dolor sit amet,consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                  Category = "Networking",
                 Organisation = "Yobuningi (Pty) Ltd",
                  ContactWebsite = "www.yobuningi.co.za",
                  ContactEmail = "info@yobuningi.co.za",
                  ContactNumber1 = "0111234567",
                  ContactNumber2 = "0111234567",
                  ContactPerson = null
                  }
              };
  
              SelectOpportunityCommand = new Command(async () =&gt; { await ShowOpportunityDetails(SelectedOpportunity); });
  
  
          }
  
  
  
          private async Task ShowOpportunityDetails(Opportunities opportunity)
          {
              var p = new NavigationParameters();
              p.Add("SelectedOpportunity", opportunity);
  
              await _navigationService.NavigateAsync("ViewOpportunityPage", p);
  
  
  
  
          }
  </code></pre>
  
  <pre class="lang-cs prettyprint-override"><code>//My Event to Command Behaviour
  
  public class ItemSelectedToCommandBehaviour : Behavior&lt;ListView&gt;
      {
          public static readonly BindableProperty CommandProperty = BindableProperty.Create(propertyName:"Command", returnType:typeof(ICommand), declaringType:typeof(ItemSelectedToCommandBehaviour));
  
          public ICommand Command
          {
              get
              {
                  return (ICommand)GetValue(CommandProperty);
              }
              set
              {
                  SetValue(CommandProperty, value);
              }
          }
  
          protected override void OnAttachedTo(ListView bindable)
          {
              base.OnAttachedTo(bindable);
  
              bindable.ItemSelected += BindableOnItemSelected;
  
  
  
              bindable.BindingContextChanged += Bindable_BindingContextChanged;
          }
  
          private void Bindable_BindingContextChanged(object sender, EventArgs e)
          {
              var lv = sender as ListView;
              BindingContext = lv?.BindingContext;
          }
  
          protected override void OnDetachingFrom(ListView bindable)
          {
              base.OnDetachingFrom(bindable);
  
              bindable.SelectedItem = null;
              bindable.ItemSelected -= BindableOnItemSelected;
              bindable.BindingContextChanged -= Bindable_BindingContextChanged;
  
          }
  
          private void BindableOnItemSelected(object sender, SelectedItemChangedEventArgs e)
          {
              Command.Execute(null);
          }
      }
  
  </code></pre>