How to refresh a observable collection in parent when it’s updated in sub page viewmodel?

I have a Maui application with tabs. On the DashboardMainPage, items are displayed in a CollectionView. From this page, I can navigate to a subpage (GoalsPage) where all items can be seen in more detail. In GoalsPage, I can navigate to another subpage (CreateGoalPage) where new goals can be saved to the local database.

The navigation flow (using shell navigation, Shell.Current.GoToAsync):

DashboardMainPage -> GoalsPage -> CreateGoalPage

public partial class DashboardMainViewModel : BaseViewModel
{
    // The repository to handle CRUD to local db
    private readonly IUnitOfWork _unitOfWork;
    public ObservableCollection<Goal> Goals { get; } = new ObservableCollection<Goal>();

    public DashboardMainViewModel(IUnitOfWork unitOfWork, INavigationService navigationService) : base(navigationService)
    {
        _unitOfWork = unitOfWork;
    }

    // This is called from OnAppearing of DashboardMainPage
    internal async Task InitializeAsync()
    {
        if (IsInitialized)  // Prevents LoadDataAsync running multiple times when navigate on and navigate back from subpage
        {
            return;
        }

        await LoadDataAsync();
    }
    
    private async Task LoadDataAsync()
    {
        Goals.Clear();

        var goalsTask =  _unitOfWork.Goal.GetAllAsync(_ => _.Completed == false);
        Goals.AddRange(goalsTask);
    }

    [RelayCommand]
    private async Task GoToGoalsPage() => await NavigationService.GoToAsync(nameof(GoalsPage));
}

public partial class GoalsViewModel : BaseViewModel
{
    private readonly IUnitOfWork _unitOfWork;
    public ObservableCollection<Goal> OnGoingGoals { get; } = new ObservableCollection<Goal>();
    public ObservableCollection<Goal> CompletedGoals { get; } = new ObservableCollection<Goal>();

    public GoalsViewModel(IUnitOfWork unitOfWork, INavigationService navigationService) : base(navigationService)
    {
        _unitOfWork = unitOfWork;     
    }
    
    // This is called from OnAppearing of DashboardMainPage
    internal async Task InitializeAsync()
    {
        if (IsInitialized) // Prevents LoadDataAsync running multiple times when navigate on and navigate back from subpage
        {
            return;
        }

        await LoadDataAsync();
    }

    private async Task LoadDataAsync()
    {
        OnGoingGoals.Clear();
        CompletedGoals.Clear();

        var goals = await _unitOfWork.Goal.GetAllAsync();
        var completed = goals.Where(_ => _.IsCompleted).OrderByDescending(_ => _.Completed.Date);

        OnGoingGoals.AddRange(goals.Where(_ => !_.IsCompleted));
        CompletedGoals.AddRange(completed);
    }

    [RelayCommand]
    private async Task GoToGoalCreatePage()
    {
        var goal = new Goal();
        
        var parameters = new Dictionary<string, object> {
            { nameof(Goal), goal }
        };
        await NavigationService.GoToAsync(nameof(GoalCreatePage), parameters);
    }
}

[QueryProperty(nameof(Goal), nameof(Goal))]
[QueryProperty(nameof(IsEdit), nameof(IsEdit))]
public partial class GoalCreateViewModel : BaseViewModel
{
    // The repository to handle CRUD to local db
    private readonly IUnitOfWork _unitOfWork;

    [ObservableProperty]
    private Goal _goal;

    public GoalCreateViewModel(IUnitOfWork unitOfWork, INavigationService navigationService) : base(navigationService)
    {
        _unitOfWork = unitOfWork;
    }

    [RelayCommand]
    private async Task Save()
    {
        var savedGoal = await _unitOfWork.Goal.SaveAsync(Goal);
        if (savedGoal is not null)
        {
            // should I trigger here a weakreference to call item in the both parent vms?
            
            // Navigate back to GoalsPage
            await NavigationService.GoBackAsync();
        }
    }
}

QUESTIONS
When a new goal is added in the sub-sub page, how is it possible to update the two parent pages?

  • Should I use weakreference (seems against mvvm)?
  • The fact I am using twice the same list, is there a way I can make a single observable collection which can be reached in all VM? (DashboardMainViewModel , GoalsViewModel and CreateGoalViewModel) and when locally is saved I could just add as Goals.Add(NewGoal)? Should it be part of the BaseViewModel?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật