Replies: 3 comments 4 replies
-
If you are trying to update an object inside a ObservableCollection after page has loaded you can try something like the following. namespace NerdNewsNavigator2.Model;
/// <summary>
/// A class for storing <see cref="Download"/> in a Database.
/// </summary>
[Table("Downloads")]
public partial class Download : ObservableObject
{
[PrimaryKey, AutoIncrement, Column("Id")]
public int Id { get; set; }
[ObservableProperty]
private string _copyRight;
[ObservableProperty]
private string _fileName;
[ObservableProperty]
private bool _deleted;
} That above is part of model file that I use. Also adding: /// <summary>
/// An <see cref="ObservableCollection{T}"/> of downloaded <see cref="Download"/> managed by this class.
/// </summary>
[ObservableProperty]
private ObservableCollection<Download> _downloadedShows; Adding |
Beta Was this translation helpful? Give feedback.
-
Of the two options presented, I've often taken the second route. Although tedious it's pretty straightforward and provides an opportunity to pull in data from other sources when creating the ViewModel. As an aside for something I've seen elsewhere in this thread, you don't need an
so it only gets bound to once and then use |
Beta Was this translation helpful? Give feedback.
-
I am just starting out with MAUI and I have the same exact question so is still using [ObservableProperty] inside of the model is the way to go ? it doesn't feel right D: |
Beta Was this translation helpful? Give feedback.
-
Problem
I am just starting out with MAUI and was using the MVVM Community Toolkit as recommended in various tutorials.
I was pretty happy with my Model logic being completely clean and not using any MAUI specific code at all.
But than I encountered the problem that observing a complete object does not work as I expected.
Using this code and Binding to
WorkTimeTracker.StartTime
does not seem to update the UI parts that are displayingWorkTimeTracker .WorkTime
etc.Solution?
I can only see two solutions to this problem:
1) Using observable property attributes in the Model
WorkTimeTracker .StartTime
also raises the question whether the View should know about the Model at all2) Wrap every Model property in a ViewModel property and call
OnPropertyChanged
WorkTimeTracker
in the ViewModel to know what changedMaybe I am just missing something here. But most of the Tutorials seem to just stop before the Model gets too complex.
Or maybe I am just being too puristic here?
Beta Was this translation helpful? Give feedback.
All reactions