Xamarin.Forms MVVM with XAML [6 of 11]

Play Xamarin.Forms MVVM with XAML [6 of 11]

The Discussion

  • User profile image
    Mario Vrhoci

    Hi!
    How I can create MVVM XAMLUI.ViewModels, MainPageViewModel.cs?
    It is not par of this video tutorial.
    Thank You!
    Best Regards,
    Mario

  • User profile image
    MattSoucoup
    @Mario Vrhoci: Hi Mario - if you go to the GitHub repo there will be a code example you can download. Essentially you'll need to create a class and make sure it implements the INotifyProperty changed interface.
  • User profile image
    Citaro

    May I know what is under the "public MainPageViewModel()"? It wasn't shown in this video or video 5 of 11 either. Thanks

  • User profile image
    Citaro

    Sorry, I mean do we create this MainPageViewModel.cs as a new class under "XAMLUI"?

  • User profile image
    Greg

    It probably is not a good idea to hide code during a tutorial.Line:10 What is the code hidden under
    public MainPageViewModel()...

  • User profile image
    Amin

    Thank you for the short and sweet tutorials. I love what you are doing and what you have done with Xamarin. But fellows, we need better tooling since, based on this video, there's just too much typing and details to remember for doing something so simple. Can you make it like WinForm where you drag and drop a control and double click on it for the code-behind event handling, write your code, and move on to better things in life?

  • User profile image
    Kyle

    Hi I am following your tutorial on Xamarin and I've encountered a problem when 'clicking' the save button I'm getting a null reference exception. Any help would be appreciated. Thanks Kyle.

  • User profile image
    Carlos

    Hi, thanks for the tutorial, helped a lot for starts. The Save command was declared as "SaveCommand" but in xaml you binded "SaveNoteCommand" (and same for the Erase command) so should the commands function? ;)


    Got the same problem as Kyle, null reference exception. Then i used:

    ObservableCollection<string> AllNotes = new ObservableCollection<string>();

    instead of:

    public ObservableCollection<string> AllNotes { get; set; }

    But the data does not appear in the label with the {Binding .}

  • User profile image
    IVSoftware
    Carlos, kudos for catching the missing initialization for AllNotes, but try doing it like so:

    public ObservableCollection AllNotes { get; set; } = new ObservableCollection();

    I believe the visibility issue in your code might be the result of omitting the 'public' keyword. I notice you also changed the AllNotes property into a field instead. Might be better to keep it as a property {get; set;} but then apply your initializer to that as shown.

    Happy coding!
  • User profile image
    meir

    hi
    I created the MainPageViewModel.cs when i try to add xlmns:local statement I get an error saying "the property local not found in type "ContentPage"??

    Looking forward to your help in this

    Regards

    Meir

  • User profile image
    meir

    Please ignore my above comment .. Silly Typo error on my side!!!

    Meir

  • User profile image
    Carlos

    IVSoftware, thank you for your help. ASAP i will try it.

Add Your 2 Cents