1

Im working on a xamarin project where you can toggle every object in the listview to show more information. So the toggle worked until I tried to sort the list after Id number. Do someone have a solution for this kind of problem?

Code for toggle:

public void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
       {
           
           var vm = BindingContext as OrderViewModel;
           var order = e.Item as Order;
           vm.HideOrShowOrder(order);
           
       } 
 

//HideorshowOrder method code:
public void HideOrShowOrder(Order order)
       {
           order.isVisible = true;
           UpdateOrder(order);

           if (_oldOrder == order)
           {
               
               order.isVisible = !order.isVisible;
               UpdateOrder(order);
           }
           else
           {
               if (_oldOrder != null)
               {
                   
                   _oldOrder.isVisible = false;
                   UpdateOrder(_oldOrder);
               }
               
               order.isVisible = true;
               UpdateOrder(order);
           }

           _oldOrder = order;


       }
//And the code for sorting the list:

public void sortedList()
       {
           var sortedList = App.Order.OrderList.OrderBy(i => i.Id).Reverse().ToList();
           orderViewList.ItemsSource = sortedList;
       } 

orderViewList is the listView name in the XAML file. So the hideOrShow method doesn't get called and i don't know why?

fredsoftx
  • 13
  • 4
  • Are you sure the method isn't being called, as opposed to being called and failing? – Jason May 18 '21 at 17:09
  • When im stepping thru the code, it lands on the method but not going in and execute the code inside so probably it trying to call but fails.. – fredsoftx May 18 '21 at 17:18
  • 1) From what method do you call `sortedList()`? 2) What happens if you change that method so it sets ItemsSource, but doesn't change sort order? `orderViewList.ItemsSource = App.Order.OrderList;`? I'm exploring whether something is not quite "ready" to be clicked on. – ToolmakerSteve May 18 '21 at 19:13
  • Yeah thats maybe a solution.. I solved the problem by sorting the list when i fetched thru the API in the viewmodel instead. But still wondering what happened with the tap function.. – fredsoftx May 18 '21 at 19:52

0 Answers0