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

Xamarin.Froms OnPropertyChanged from another Page

$
0
0

I have a tabbed page with some tab.

In two of this tabs I have a list.

When a record is added/edited in the first list I need to refresh the second list,

because in the model of the second list there is a boolean property that take care to hide or not an image.

This behavior doesn't works.

If I set

SecondList = ObservableCollection<SecondClass>();

the second list is update correctly and it is show empty.

If I change the second list property ShowImage the list isn't updated, the variable is, but the ListView isn't.

If I go on the second tab and add manually a record, the second list is correcty updated.

This is the code that I use for do this:

MessagingCenter.Subscribe<RigaDettaglioViewModel>(this, Costanti.ChiaviMessaggi.AggiornaListaRigheWo.ToString(), (sender) => {
                RaisePropertyChanged(() => ListaWORighe); // Update the first list.
                RaisePropertyChanged(() => ListaSpese); // Update the second list.
            });

RaisePropertyChanged:

public void RaisePropertyChanged<T>(Expression<Func<T>> Property) {
    var name = GetMemberInfo(Property).Name;
    OnPropertyChanged(name);
}

XAML (VolosBaseButtonView is a Grid that contains an Image view):

<view:VolosBaseButtonView 
    Grid.Row="0" Grid.Column="4"
    SoloIcona="True"  
    ColoreIcona="Red"
    Icon="{core:Icona Warning}"                                             
    IsVisible="{Binding ShowImage}" 
    CommandParameter="{Binding .}"
    Command="{Binding BindingContext.ApriInfoSpesaCommand, Source={x:Reference SpeseViewPage}}"/>

ListaSpese (the second list):

public ObservableCollection<WorkOrderDettaglioListaSpese> ListaSpese {
        get {
            ObservableCollection<WorkOrderDettaglioListaSpese> Lista = null;

            if (WoDett.ListaSpese != null) {
                var ListaOrdinata = WoDett.ListaSpese.Where(R => !Utility.FlagTrattAnnullato(R.FlagTratt)).OrderByDescending(R => R.DataSpesa).ToList();
                // Devo controllare, per ogni spesa, se c'è un intervento in quella data, altrimenti NoInterventoInData = true;
                WorkOrderService.ControllaDateIntervento(ListaOrdinata);
                Lista = new ObservableCollection<WorkOrderDettaglioListaSpese>(ListaOrdinata);
            }

            return Lista;
        }
        set {
            WoDett.ListaSpese = new List<WorkOrderDettaglioListaSpese>(value);
            RaisePropertyChanged(() => ListaSpese);
        }
    }

How can I update the list that are in the second tab correctly?

Thank you!

EDIT

Link to the sample project.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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