From Code-Behind Code to MVVM with XAML and C#

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ •

  •  3 роки тому +7

    Thank you! Finally a concise and smart way to explain MVVM.

  • @matheushenrique4844
    @matheushenrique4844 2 роки тому +3

    MVVM stands for Model-View-ViewModel, so i naturally imagine 3 files, the View, the ViewModel and the Model, but here and all other videos about it i only see 2 files being implemented, the View and the ViewModel but not the Model... so why it's not implemented? and what is the diference (when the Model file is implemented) on ViewModel?

  • @anandshindey
    @anandshindey 3 роки тому

    Good stuff. MVVM is a life saver. The number of times my UI has changed, I would go crazy without MVVM. Cheers.

    • @jfversluis
      @jfversluis  3 роки тому

      Haha that is great to hear!

  • @DifferentTurn
    @DifferentTurn 3 роки тому +1

    Gerald, appreciate your work! Awesome and helpful vid :)

    • @jfversluis
      @jfversluis  3 роки тому +1

      Thanks for taking the time to let me know Alexey!

  • @GeorgAubele
    @GeorgAubele Місяць тому

    Thanks - good to understand!

  • @dddanielsr
    @dddanielsr 2 роки тому

    This is defenitely the best video about mvvm.
    Quick question, Everyone uses fields and properties, you just skip the field and use the property, directly why is that?

  • @rickshadle3753
    @rickshadle3753 3 роки тому +2

    Love the video. Communication skills are excellent. Would it be possible to incorporate MVVM demo into a Flyout type project?

    • @jfversluis
      @jfversluis  3 роки тому +1

      You mean using MVVM with a Flyout page?

  • @davidkim7812
    @davidkim7812 Рік тому

    Hi Gerald, Thank you very much for your video.

  • @brilliantmaenetja3430
    @brilliantmaenetja3430 2 роки тому

    Excellent Video, excellent explanation. 🔥

  • @mdottech6502
    @mdottech6502 2 роки тому

    Hello sir , Your way to explain is super easy but videos should have an order . And One can easily learn by following the playlist, I mean there should be hierarchy of concepts from scratch to advance . Thanks

    • @jfversluis
      @jfversluis  2 роки тому

      Thanks for the suggestion!

  • @mothunderz
    @mothunderz 2 роки тому

    Dankjewel man, mega goede uitleg!

    • @jfversluis
      @jfversluis  2 роки тому

      Goed om te horen, dank je wel!

  • @MrDinakdakan
    @MrDinakdakan 2 роки тому

    thank you, question how do i call a control event with a command, the control is in a page content

  • @sentrycod2373
    @sentrycod2373 3 роки тому

    Awesome vid! Could you do a full series on all things mvvm?

    • @jfversluis
      @jfversluis  3 роки тому +1

      I think a lot of people would like that. Let me see what I can do… do you have an idea of what you’d want to learn?

  • @mimouneh7055
    @mimouneh7055 3 роки тому

    Hi Gerald, excellent video, i have a little question, we execute the commands from the xaml side of our view, but its a violation if we do it from code-behind? Let me explain, I need to populate a ListView when the view is loaded and i achieved this by:
    // C# code
    MyViewModel vm = (MyViewModel)BindingContext;
    vm.PopulateListViewCommand.Execute(null);
    //
    Using this in the code behind, its a MVVM violation?

    • @jfversluis
      @jfversluis  3 роки тому

      Basically everything you do in your code-behind is a violation if you strictly want to follow it

  • @Cvijo123
    @Cvijo123 3 роки тому

    Nice video as always, love watching them as they are short and to the point ... but can you make some video about MVVM frameworks (CrosMVVM, LightMVVM, FreshMVVM ...) I think some of them are discontinued and will not be maintained anymore .. like LightMVVM .. some pros and cons (this one is lightest and fastest but doesn't have this or that or CrossMVVM has it all but its robust)

    • @jfversluis
      @jfversluis  3 роки тому

      Thanks Matija! I will look into that! Note that MvvmLight (I assume you mean :)) is no longer maintained and you should now use CommunityToolkit.Mvvm which is the successor!

  • @richardalain2988
    @richardalain2988 3 роки тому

    Great video! A video about binding will be nice

    • @jfversluis
      @jfversluis  3 роки тому

      I already have a playlist about some of that, does that cover your questions? ua-cam.com/play/PLfbOp004UaYWOuVUuEtGlpkDIC1houhn_.html

  • @revtane9
    @revtane9 3 роки тому

    Amazing as always... bravo bravo... gonna try this later on m1 mac mini

    • @jfversluis
      @jfversluis  3 роки тому +1

      Thanks! Let me know how that goes!

    • @revtane9
      @revtane9 3 роки тому +1

      @@jfversluis sure, will do

  • @MrRobravens
    @MrRobravens 2 роки тому

    Is that “helper method” a requirement or something that’s only needed in certain cases?

    • @jfversluis
      @jfversluis  2 роки тому +1

      Which helper method is that?

    • @MrRobravens
      @MrRobravens 2 роки тому

      @@jfversluis does the PropertyChanged event implementaton get invoked automatically and change the XAML or is invoking it manually as you have done in the OnPropertyChanged method required?

    • @jfversluis
      @jfversluis  2 роки тому +1

      @@MrRobravens Ah you will need that, but I think it's there by default on all the Xamarin.Forms controls. It will be invoked automatically by the XAML binding engine indeed

    • @MrRobravens
      @MrRobravens 2 роки тому

      @@jfversluis perfect thank you!

  • @KeesAlderliesten
    @KeesAlderliesten 3 роки тому

    Hi Gerald. I specify the ViewModel in the xaml using a section. Intellisense works great then. But if I initialize the binding context in the page constructor (because I have to pass some parameters) the ViewModel gets initialized twice, once without and once with the parameter(s). Is there a way to prevent this? Or doing it a better way?

    • @jfversluis
      @jfversluis  2 роки тому

      You can pass parameters through XAML, have a look at this post: xamgirl.com/xaml-tips-and-tricks/ not pretty, but you can :)

    • @KeesAlderliesten
      @KeesAlderliesten 2 роки тому

      @@jfversluis I don't think this is what mean. I open a new page for a tapped product or something with new Page(productid). In the codebehind of this page I set de BindingContext to new ViewModel(productId) in the constructor of that page that accepts this parameter. So there are 2 constructors in this viewmodel, one without and one with a parameter. This viewmodel is referenced in the xaml so intellisense works correct. But when this page in opened the reference in the xaml causes the viewmodel te be initialized with a call to the default constructor and the call to new ViewModel(id) in the page codebehind causes the ViewModel to be initialized again with the call to de contructor accepting that parameter. It works, but costs time and extra resources. What is the 'normal' way to do this? Last solution a came up with is: because the reference in the xaml initializes the viewmodel already, so in the page codebehind I only set a property of the BindingContext to the productId. (Or call a method if it needs te be async)

    • @jfversluis
      @jfversluis  2 роки тому +1

      @@KeesAlderliesten There is a lot in here 😄 not sure if UA-cam comments is the best way to answer this. I think you might want to look at compiled bindings which still gives you IntelliSense but doesn't create an instance of your view model: docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/data-binding/compiled-bindings
      I think when I used to build this I would just have 1 constructor and pass in a -1 or null or something whenever I needed something new. But that's mostly dependant on preference and requirements.

    • @KeesAlderliesten
      @KeesAlderliesten 2 роки тому

      @@jfversluis Thanks! :-)

    • @jfversluis
      @jfversluis  2 роки тому

      @@KeesAlderliesten No problem at all! Send me an email or something if you still want to know something :)

  • @FreyClante
    @FreyClante 2 роки тому

    Hi is it possible to inject the view model into the code-behind. Im using Autofac, but Im having trouble cause it seems that WPF only calls the default constructor of the code-behind and thus my injected types doesn't get injected.

    • @jfversluis
      @jfversluis  2 роки тому

      Hm not sure about WPF to be honest...

  • @darbix2006
    @darbix2006 3 роки тому

    If I have a single button to push a new Navigation page, should it's function be included in the Model class or simply implement the OnClick function in code-behind?

    • @jfversluis
      @jfversluis  2 роки тому +1

      If you want to do it "right" everything should be in the model :)

  • @darrabam
    @darrabam 3 роки тому

    10:45 Yes please!!

  • @sharafudeen4734
    @sharafudeen4734 3 роки тому

    I would like to know the best way to implement business logic in MVVM pattern. This is because in the nearest future I migrate to MAUI.

    • @jfversluis
      @jfversluis  3 роки тому +1

      I think that would be a hard topic. That depends very much on what you’re trying to do :)

  • @soundcheck001
    @soundcheck001 3 роки тому

    Great video. If you can make a video about MVVM basics!!!

    • @jfversluis
      @jfversluis  3 роки тому +1

      I'm planning to do something around that. Stay tuned!

  • @danyfernandorivera3696
    @danyfernandorivera3696 2 роки тому

    Hi Gerald I'm trying to use command for activity indicator Command Visibility = true -> Task -> Visibility = false, is it posible?

    • @jfversluis
      @jfversluis  2 роки тому +1

      That should definitely be possible!

    • @danyfernandorivera3696
      @danyfernandorivera3696 2 роки тому

      @Gerald Versluis Thanks for answer, the actual fact is that keep in the first on property changed command, looking for a way to recall

    • @danyfernandorivera3696
      @danyfernandorivera3696 2 роки тому

      I have solved this issue, without using command, but activating property in the right moment, thanks for the video that was the base to achieve use of activity indicator at demmand

  • @checox1909
    @checox1909 3 роки тому

    I love MVVM pattern ♥.....(btw) let you know, I finally got my macbook pro, I haven't installed anything yet but when I set it ready, I'll let you know about my experience

  • @renich6666
    @renich6666 3 роки тому

    Can you clarify something? Can maui work under net core on desktop like avalonia does?

    • @jfversluis
      @jfversluis  3 роки тому

      Hm not sure what you mean? It will use .NET 6, which is the continuation of .NET Core, so yeah it should be able to run on a desktop with it's own runtime version

  • @philippedoumet6073
    @philippedoumet6073 3 роки тому

    Hello Gerald, how can I make a page the "main page" while running the app?

    • @jfversluis
      @jfversluis  3 роки тому

      Assign a new page to the Application.Current.MainPage property :)

    • @philippedoumet6073
      @philippedoumet6073 3 роки тому

      @@jfversluis Ohh okay. ANd in my code what do I do?

    • @jfversluis
      @jfversluis  3 роки тому

      I guess something like; Application.Current.MainPage = new MyPage();

    • @philippedoumet6073
      @philippedoumet6073 3 роки тому

      @@jfversluis okay! Thank you.

  • @michelchaghoury870
    @michelchaghoury870 3 роки тому

    gr8 vid please keep going

    • @jfversluis
      @jfversluis  3 роки тому

      Thanks, will do! Anything you'd like to see in regard to MVVM?

    • @michelchaghoury870
      @michelchaghoury870 3 роки тому +1

      @@jfversluis if u can in the future make like a todo list app CRUD operations and UI made with MVVM but without MVVM Frameworks or packages to be albe to understand how things works and tnx a lottt

  • @parsalotfy
    @parsalotfy 3 роки тому

    windows forms uses Code-Behind right ?

    • @jfversluis
      @jfversluis  3 роки тому

      It does! But I don’t think WinForms has the means to support MVVM built-in, but not 100% sure on this

  • @varshapatil8229
    @varshapatil8229 3 роки тому

    Osum..pls show implemention of barcode stiker printing through bluetooth printer in xamarin.

    • @jfversluis
      @jfversluis  3 роки тому

      I'm sorry, I don't have such a printer around so I can't make that video :)
      Maybe this helps: www.xamboy.com/2020/04/20/bluetooth-printing-in-xamarin-forms-using-shiny/

    • @varshapatil8229
      @varshapatil8229 3 роки тому

      @@jfversluis thanks. but it's printing only string text,not barcode..

  • @r.gopalakrishnan6926
    @r.gopalakrishnan6926 3 роки тому

    Great

    • @jfversluis
      @jfversluis  3 роки тому +1

      Glad it was helpful to you!

  • @memsom
    @memsom 3 роки тому

    I would use ICommand not Command, especially because your Command implementation might not be a Command instance

    • @jfversluis
      @jfversluis  3 роки тому

      Good! More advanced stuff for a next video ;)

  • @renzorivera1996
    @renzorivera1996 2 роки тому

    El único que pudo explicar por qué solo se almacenaba el valor en la propiedad, pero no cambiaba el valor en el objeto.