How to show a WPF dialog using MVVM in C# with a mediator

Sdílet
Vložit
  • čas přidán 7. 09. 2024
  • Tutorial that shows how to show a WPF dialog from a view-model when using MVVM by using a mediator service to abstract view concerns.
    Code:
    1drv.ms/u/s!Ag...
    Video with better audio:
    1drv.ms/v/s!Ag...
    #wpf #mvvm #dcomengineering
  • Věda a technologie

Komentáře • 74

  • @hussainhussaini2267
    @hussainhussaini2267 Před 3 lety +1

    I was searching weeks for this solution. Thank you!

  • @kajij
    @kajij Před 5 lety +1

    Thanks for providing the corrected video in your description!

  • @ryanweldin553
    @ryanweldin553 Před 7 lety +30

    Love your videos, but the audio is very low even with max volume on several of my devices/computers. Can this be improved? Thank you.

    • @DX7Dev
      @DX7Dev  Před 7 lety +1

      I believe I have corrected this on newer videos. I will monitor this!

    • @stevenaughton9372
      @stevenaughton9372 Před 4 lety +3

      This is more of a problem because we have set the playback volume to the max, and when the ads play they are super loud.

    • @watherby29
      @watherby29 Před 3 lety

      I also can't hear the audio watching the first Bourne on the small player here on the right.

  • @ProgrammingMadeEZ
    @ProgrammingMadeEZ Před 7 lety +4

    Good to see you posting again.

  • @EricAnastas
    @EricAnastas Před 6 lety +2

    This is nitpicking, but this message (10:07) should be something like "is already mapped to type {Mappings[typeofTViewModel]}" to show the current mapping not the new requested mapping

  • @bomfirit75
    @bomfirit75 Před 2 lety +1

    Thanks. Your tutorial helped me a lot.

  • @EnimaIffets
    @EnimaIffets Před 7 lety +2

    Very very nice !!
    I would give you 1000 "thumbs up" if it was possible :-)
    and good to see you posting again, long time i was waiting for new tutorials!

    • @DX7Dev
      @DX7Dev  Před 7 lety

      More to come.. I have a list..

  • @alonlevi80
    @alonlevi80 Před 3 lety +1

    Thanks for the detailed video. Just started to lern WPF with MVVM. Haven't found a single example for creating a Modal dialog..... why not start from simple yet not perfect way of implementing it and then develop it more and more?? This is really frustrating for me...

  • @teamRizek
    @teamRizek Před 7 lety +1

    I'm glad you are back!

  • @FuzzyDPozzy
    @FuzzyDPozzy Před 3 lety +1

    It freaking worked!!! unbeliavable :d:D :D :D

  • @MrEvgeny1984
    @MrEvgeny1984 Před 7 lety +2

    Thank You for sharing the idea, one problem that I see, that your approach can only work with windows applications. My requirement was to implement it in context of core library to use it with wpf and also xamarin plattforms.
    So I have used an other approach by using the Action class and Callbacks.

    • @DX7Dev
      @DX7Dev  Před 7 lety

      I haven't built a Xamarin application, but you would have to adapt a solution for it. The concept is the same: create an abstraction by defining the appropriate interfaces, and create a mediator to handle the actual display of the dialog. A single solution for both Xamarin and WPF could be tricky if there isn't any commonality between them, but probably very possible. I would have to take a deeper look at Xamarin to be more helpful.

    • @seemovielove3597
      @seemovielove3597 Před 4 lety

      can you share your code for your approach using action and callbacks? Thanks

  • @Aram198624
    @Aram198624 Před 5 lety

    It was quite to the point, well done!

  • @francoisdeklerk1266
    @francoisdeklerk1266 Před 7 lety +5

    Volume?

  • @handypda
    @handypda Před 2 lety

    Good work!

  • @user-in9hx8em7u
    @user-in9hx8em7u Před 6 lety +5

    can`t hear anything

  • @pidunate
    @pidunate Před rokem +2

    Great content, but the audio is unusually low.

  • @pimor2315
    @pimor2315 Před 7 lety +2

    Very nice, I like the idea. I see only one issue. owner will always be read as null. I have modified the constructor and owner field so I can set it later, however I'm not sure if i should do that.

    • @DX7Dev
      @DX7Dev  Před 7 lety

      +Piotr Morawski You set the owner in App.xaml when you instantiate the dialog service via its constructor. Typically to MainWindow. Shouldn't be null. It would be null in a unit test though, since there is no ui/owner

    • @pimor2315
      @pimor2315 Před 7 lety

      DCOM Engineering, LLC Yes I know, however later you set MainWindow. For example if I want to set startuplocation of the dialog to a parentcenter, it will not work, because the owner is null. Any ideas?

  • @stephendougherty9383
    @stephendougherty9383 Před 7 lety

    really liked this approach - my only issue is incorporating it with MEF. Still struggling to get my head around a lot of WPF and MVVM concepts

    • @DX7Dev
      @DX7Dev  Před 7 lety

      If you can elaborate I can probably help with your MEF issue.

    • @stephendougherty9383
      @stephendougherty9383 Před 7 lety

      Thanks for the reply - I have one more thing to try and figure it out on my own, but will certainly ask if it does not work

  • @willijd4
    @willijd4 Před 6 lety +1

    Great video! Thanks for linking to your project. One question, why does the IDialog interface need a reference to the Window Owner?

  • @Quadrition333
    @Quadrition333 Před 5 lety

    How do I implement dialogService in opened dialog, if I want to open more dialogs from already opened dialog?

  • @wittttttt
    @wittttttt Před 6 lety

    12:12 Is it really necessary? Isn't viewModel disposed with the view (after it's closed)? Which means that all event handlers are disposed as well, aren't they? Am I missing something? Can you please explain?

    • @ondrejexner3688
      @ondrejexner3688 Před 6 lety

      If you don't need the viewModel anymore then yes, it gets disposed. But there are often situations when you need the data from the dialog window returned. For example: create_customer/order/etc dialog. Thats why you create the viewModel before calling the ShowDialog method.

  • @edyzere
    @edyzere Před 6 lety

    I love your framework and using it in my proyect thanks a lot. I have two questions with this video. How can adapt the code if the owner is a user control instead of a window. And how can i adapt it if a have to get two strings back from the dialog like if i want to use it as a login form? Thanks in advance.

  • @scotolivera8207
    @scotolivera8207 Před 3 lety

    Thanks, is it possible to fix the download link for the source code?

  • @ginanjarbambang7122
    @ginanjarbambang7122 Před 5 lety +1

    very nice, but this is very hard to me, only to show dialog. :)

  • @dushhettiarachchi8977
    @dushhettiarachchi8977 Před 7 lety

    Thanks for your video.
    I have used Prism interaction triggers to open popup. What are the benefit of using Dialog service (your method) over prism interaction?
    Which one you recommend?

  • @seemovielove3597
    @seemovielove3597 Před 4 lety

    Do you have a service for calling modeless dialog? Thanks

    • @DX7Dev
      @DX7Dev  Před 4 lety

      I don't, but it would be pretty easy to write one using events or a mediator. You can take this same concept and try and write your own :)

  • @mohammedkarro4383
    @mohammedkarro4383 Před 5 lety +1

    Noice!

  • @davegdn
    @davegdn Před 4 lety

    Excellent but very low volume, had to pump up volume level to hear a little

    • @DX7Dev
      @DX7Dev  Před 4 lety

      There is a link in the description to a corrected video.

  • @yanapryimak5469
    @yanapryimak5469 Před 6 lety

    Why don't you show the result in the end?

  • @themanbehindthescenes364

    I am a beginner at WPF and in C#, please I have many questions about MVVM and it would be great if you can help me, first What is MVVM ? and why are we writing so much code just to display a simple dialog ??! aren't there suppose to be some built-in classes that takes care of all that background work like in android studio and java ??? is this truly necessary ?? I've downloaded your source code and didn't understand a thing from the code. what can I do to understand what the hell is going on ?

    • @WesleysFishClub
      @WesleysFishClub Před 6 lety

      MVVM Stands for Model - View - ViewModel and is just a design pattern to build UI applications. We use this pattern to seperate UI, Logic and data which makes code re-usable, dynamic and easily unit testable. By implementing the DialogService shown in the video, you're avoiding tight coupling between your UI (View) and logic (ViewModel).
      The code shown in the video might be complex to understand if you're unfamilar with concepts such as abstraction or generics.
      Follow and listen to understand whats happening.

    • @DX7Dev
      @DX7Dev  Před 6 lety

      The primary reason for the dialog abstraction is the unit testing of the view model. You can't have dialogs showing in a unit test, and especially so in a build server. Testability, reusability and separation of logic from the view is the primary purposes of a view model. If you were writing a small CRUD application with minimal logic and no unit tests, something like this is not necessary, but its an essential pattern in medium to large code bases

    • @themanbehindthescenes364
      @themanbehindthescenes364 Před 6 lety

      Okay but I don't understand the code, where can I start with the basics of MVVM ?

    • @DX7Dev
      @DX7Dev  Před 6 lety

      See my MVVM session 1, intro video

  • @anaibrahim4361
    @anaibrahim4361 Před 2 lety

    is that all just to pop up a dialog !!!

  • @jamesshaw4089
    @jamesshaw4089 Před 6 lety

    Definitely easy to follow along with. The volume on the otherhand...that's another story. I had to play the video on my TV and turn it's volume up to 100% just to hear it. Good job otherwise!

    • @DX7Dev
      @DX7Dev  Před 6 lety

      I added a corrected volume video link in the description.

  • @mrtreynobles
    @mrtreynobles Před 5 lety

    Hi there - I really enjoy your videos. Very informative. I'm trying to implement a solution like this with a unity bootstrapper but I'm struggling on figuring out how to implement it in the bootstrapper. It might be worth noting that I'm using Prism as the mvvm framework. I know that I can load the initialize the dialog service in the main window viewmodel constructor but I know that there is probably a better way to do it in the bootstrapper. Any ideas?

  • @Joel4JC
    @Joel4JC Před 5 lety +1

    You show a link in the description with a Video with the corrected audio, why can't you just upload the Video with the corrected audio here?

  • @sha.e.sengineeringsolution1205

    How to handle dialog with ( Save, Don't Save ,Cancel )

    • @DX7Dev
      @DX7Dev  Před 4 lety

      Same way but you model your view appropriately to have that information about the dialog, such as a property with an enum that gets set

  • @chhampionsjourney
    @chhampionsjourney Před 4 lety

    After uploading did you ever hear the voice ....its very low

  • @lufog
    @lufog Před 5 lety +1

    What? I don't hear you!

    • @DX7Dev
      @DX7Dev  Před 5 lety +1

      There is a corrected video in the description

  • @signon77
    @signon77 Před 5 lety

    Potentially this might be a good video. Couldn't hear a thing though.

    • @DX7Dev
      @DX7Dev  Před 5 lety

      There is a fixed audio version in the description

  • @user-vg1ft2qf5i
    @user-vg1ft2qf5i Před 4 lety

    Please fix the volume.

  • @arkadybron1994
    @arkadybron1994 Před 2 lety

    I cant hear what you're saying.

    • @DX7Dev
      @DX7Dev  Před 2 lety +1

      Fixed the audio and there's a new link in the description

  • @TheDotnettex
    @TheDotnettex Před rokem

    WHAT????? HELLO??? IS THERE AUDIO ON THIS??? CAN YOU SPEAK UP???? Another person that has no idea how to set the correct audio level in a video....

    • @DX7Dev
      @DX7Dev  Před rokem

      There is a link to a fixed video in the video description. Sorry about that.