View Models - WPF MVVM TUTORIAL #3

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ต.ค. 2024

ความคิดเห็น • 113

  • @GetMoGaming
    @GetMoGaming 4 หลายเดือนก่อน +1

    I love it when I do little things in my app naturally coz it feels right, then see an actual programmer doing it (but like a hundred times faster xD). This is a great series btw, It's pulling everything mvvm into focus for me. 👍👍👍

  • @FISHXD10219
    @FISHXD10219 2 ปีที่แล้ว +6

    the part you are talking about how to glue the model data to a viewmodel (8:35) is just what I need! thank you for these helpful and good quality tutorial :)

  • @dasfahrer8187
    @dasfahrer8187 3 ปีที่แล้ว +3

    Propchange snippet is so useful. Thanks for that.

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว +1

      Glad it's helpful! It's definitely saved me a lot of hassle too

    • @spikecowell
      @spikecowell ปีที่แล้ว

      @@SingletonSean I've never used a snippet before. I clicked on the link and propchange.snippet showed up in it's own tab in my VS Community, but I'm still lost as to how to integrate/implement it. Can anyone help me out here? or direct me to a tutorial?

  • @nguyentrananhnguyen7900
    @nguyentrananhnguyen7900 2 ปีที่แล้ว

    i have watched a few videos about MVVM tutorials now, yours is truely for everyone, the others just assume we already know everything else

  • @ronaldnelson9385
    @ronaldnelson9385 2 ปีที่แล้ว +7

    Thank you for your tutorials! So far yours have been the best I've seen as they are easy to follow, well structured, and aren't pushing to add additional frameworks to do what MVVM was made to do. I'm watching your tutorials for a private project, we don't use WPF or MVVM where I work(yet), but I will be recommending your tutorials to my coworkers and friends that are developers.

    • @SingletonSean
      @SingletonSean  2 ปีที่แล้ว

      Thanks Ronald, glad these videos have helped! I agree that you can get pretty much everything done without frameworks in WPF. I still want to dig into a framework just to see what it's like, but for now I'll continue just rolling without a framework. Best of luck on your project!

  • @AlexReflex
    @AlexReflex ปีที่แล้ว +1

    I am (also) a C# developer, but never used WPF before. Great video series. Always rechecking your videos, when I need something :D

  • @dimime1
    @dimime1 2 ปีที่แล้ว

    The best MVVM tutorial on TH-cam!

  • @getsuha
    @getsuha 2 ปีที่แล้ว +2

    Best WPF C# contents I have ever found in youtube after searching for months. Amazing all round tutorial with exactly the speed I wanted. Thanks a ton @SingletonSean

    • @SingletonSean
      @SingletonSean  2 ปีที่แล้ว

      Fantastic Suhasis, glad this has been helpful and has a good pace!

  • @dunnoqwe
    @dunnoqwe 7 หลายเดือนก่อน

    Thanks a lot, it was a great lesson! I didn't think that it was possible to create a VM for Model to connect Model and ViewModel, it seemed to me a very interesting mechanism

  • @ingobert2328
    @ingobert2328 10 หลายเดือนก่อน

    Better than all the paid courses I know. Thank you from the bottom of my one braincell!

  • @gutibokeron
    @gutibokeron ปีที่แล้ว +1

    Thanks for all SingletonSean!
    Amazing tutorials altough sometimes pretty fast. I'm mechanical engineer although I have strong bases in programming but not as strong in Software arquitecture. I think a great idea would be creating some graphics diagrams before you start to code directly. I really believe this would help to understand this course even better!

  • @issamdak5065
    @issamdak5065 ปีที่แล้ว +10

    You are an MVVM master , my problem is that I can't digest such a lot of information, Please do you have any course where you explain logic step by step to master the MVVM pattern

  • @tarekjrd75
    @tarekjrd75 2 ปีที่แล้ว

    Thank you So much. You are helping me in a different type of project of mine and actually, i could make my own progress thanks to your help.
    Thank you second time. 🙏

  • @mrt7948
    @mrt7948 2 ปีที่แล้ว

    he is a master in software. Respect.

  • @polarisnation201
    @polarisnation201 3 ปีที่แล้ว

    I'm glad to hear that a new video has been uploaded.

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว +1

      And more on the way Polaris :)

  • @Anequit
    @Anequit 2 ปีที่แล้ว

    Wow thank you for that snippet lol such a timesaver

    • @SingletonSean
      @SingletonSean  2 ปีที่แล้ว +1

      It really is hahahah, I feel so slow without it. Glad it's helped, Anequit!

  • @MadBiker88y
    @MadBiker88y 2 ปีที่แล้ว +3

    I like your videos and appreciate the way you debug on line so we can see how you solve and diagnose issues, but was puzzled in this one at 13:20 where you comment that MVVM XAML views should not be using code behind, yet the very next step is you putting currentViewModel & datacontext into code behind on the Main Window - not sure what to take from that?
    If you view it as a temporary step before navigation is implemented, then it would have been simpler to put datacontext in each viewmodel leaving only currentViewModel to change on App.cs and that could have been declared in Xaml rather than code behind. If datacontext was declared earlier in each viewmodel (even if temporarily using xaml resources), it would have made autocompletion available on your views when binding text so your video of view creation would be much simpler - we would have understood the code much earlier.

  • @moonmadness9278
    @moonmadness9278 2 ปีที่แล้ว

    Great content and great pace! Third or fourth MVVM video I watch and by far the best!

    • @SingletonSean
      @SingletonSean  2 ปีที่แล้ว

      Thank you moonmadness, glad this one was helpful!

  • @MagoMakes
    @MagoMakes 2 ปีที่แล้ว +9

    Hi. Good quality tutorial. Just a little constructive feedback - maybe slow your presentation down a little? Learning theory dictates that learners need pauses and 'beats' to assimilate/accommodate information. Great quality stuff, but hampered by not taking a breath. I realise it's a sad result of contemporary pressures (everything has to be lightning fast and 'not too long' due to worsening attention spans).

    • @gamagetf
      @gamagetf 7 หลายเดือนก่อน +3

      Pause the video.

  • @fedorpinega2507
    @fedorpinega2507 ปีที่แล้ว

    Thanks for video! Sounds funny on 0.5 speed)

  • @yangthomas5064
    @yangthomas5064 ปีที่แล้ว

    amazing tutorial

  • @ivandrofly
    @ivandrofly ปีที่แล้ว +1

    6:40 - Why binding to a property that doesn't implement INotifyOnPropertyChanged can cause memory leaks?

  • @NoAlias536
    @NoAlias536 2 ปีที่แล้ว +2

    Nice tutorial. But I would like to see how would you do when the application gets more complex. I mean when you need more methods to do specific stuffs and how you separate the viewmodel from the model.
    I'm asking this because I have an application that connects to an API that have to do a lot of stuffs and I have many methods in the view model because there is where I have other variables that I need and I cannot move them to the model.
    In short words maybe you can explain more the right way to separate models and view models when you need to use many different methods. Where and how to put them?

    • @vic_epsy
      @vic_epsy 11 หลายเดือนก่อน

      ViewModel and Models are already separated..
      Viewmodel is just what the VIew will get, you are not forced to map Model to ViewModel 1 to 1,

  • @franakciuleney280
    @franakciuleney280 ปีที่แล้ว

    Very nice!

  • @bearzal2234
    @bearzal2234 ปีที่แล้ว +1

    This is a great video!!
    I have a question, at 11:28 we have generated mock data in ReservationListingViewModel constructor, I have real data coming from a data access layer method and I want to add this data into _reservations list as bulk but I cannot cast it. How can I accomplish this?

  • @nohopestage
    @nohopestage 3 ปีที่แล้ว

    Great one. I like the way you pronounce "item" haha

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว +2

      Thanks nohopestage! Yeah idk people tell me I say other words different too. I have some kind of slight accent, I just don't know what it is lolol.

  • @CyleThomas
    @CyleThomas 2 ปีที่แล้ว

    Love the tutorials, but I have to say I had an issue when trying to bind my properties, I kept getting issues claiming "InvalidOperationException: A TwoWay or OneWayToSource binding cannot work on the read-only property 'Size' " I tried all binding options out of curiosity and continued to get the same result. I would love to use this method for making a large view for this form I've created.

  • @trustingod0
    @trustingod0 4 หลายเดือนก่อน

    At 11:22 you are adding Reservation Type Items to the Listview, but for some reason the only Object intellisense shows is the Reservation object. when I try to do a New RoomID, intellisense does not show it. Is there somewhere that I am missing a reference to these properties?

  • @domenicoboassi282
    @domenicoboassi282 2 ปีที่แล้ว +1

    Absolutely amazing series, really helpful. Can I just ask one question? I have a view, in which I have a list of objects which we'll call Class A. As per your video I have created a viewmodel class of the model class A, so that it can interface with the view. But I also have a list, made up of another model class (Class B) inside the original class. I don't need to show this in the view, as each list item of Class A has a button to show the list of list items of Class B (so as a separate view), but now I'm implementing commands and I need to save list A, so I also need lists of B inside the viewmodel of A, but how do I do that? I'm sorry if it's not well explained, and thank you.

    • @domenicoboassi282
      @domenicoboassi282 2 ปีที่แล้ว +1

      Also let's say that you wanted to represent RoomID in the ViewModel of Reservation as a RoomID, not as a string, how would you do that too?

  • @matthiaseckinger2179
    @matthiaseckinger2179 ปีที่แล้ว

    Minute 07:40 - my Class RoomID is avalible but this is not correct, what am i doing wrong...? thanks for this usefull content!

  • @snr2196
    @snr2196 ปีที่แล้ว

    Why don't you bind View and ViewModels with the TwoWay binding instead of using INotifyChange ?

  • @Jeremygrmn
    @Jeremygrmn 3 ปีที่แล้ว +2

    Hey Sean! When you created the ReservationViewModel that extended VMBase, why didn't you have to call OnPropertyChanged on the mapped properties from the Reservation model?

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว +1

      Good question Jeremy! Since those properties are read-only (only have a getter), we've enforced that the view model can never change them. That said, we'll never have to tell the view about those properties changing, so we'll never have to raise OnPropertyChanged.
      Let me know if you have any other questions about that! I feel like I used to always automatically make every view model property have a getter AND setter, when in reality I was never using the setter.

    • @MegaGnads
      @MegaGnads 3 ปีที่แล้ว

      @@SingletonSean What if we wanted to be able to update those? Just add the setter with OnPropertyChanged event?

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว

      @MegaGnads Correcto!

  • @angelotrivelli
    @angelotrivelli 3 ปีที่แล้ว +1

    Thanks for the nice explanation!
    9:24, I notice that you exposed your private ObservableCollection field as an IEnumerable property.
    But that prevents the UI Binding from seeing the CollectionChanged events as you add or remove reservations, right? Don't you want the Binding to detect when reservations are added/removed?

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว +2

      Good point angelo! Since the underlying IEnumerable is an ObservableCollection instance, I believe the UI will still be able to hook into the CollectionChanged event.

    • @angelotrivelli
      @angelotrivelli 3 ปีที่แล้ว +1

      @@SingletonSean You're right, just confirmed it for myself.
      But how? I thought the whole point of interfaces (in this case IEnumerable) was to mask the implementation of a concrete object and provide only the methods/properties defined by the interface (in the case of IEnumerable that would be "GetEnumerator()"). How can an event from ObservableCollection "get through" IEnumerable?

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว +3

      Your interpretation of interfaces masking implementations is certainly correct. WPF bindings are a bit magical though, and can "dynamically" bind to properties on objects.
      In fact, I could just expose all of my bindings as "object". For example, views bind to the DataContext property. However, the type of DataContext is just "object".
      Just another day in the wild world of WPF.

    • @andiwand1119
      @andiwand1119 2 ปีที่แล้ว +2

      @@angelotrivelli Even though your Data property is returned with the type of IEnumerable, the object itself is still an ObservableCollection. WPF can just use the 'is' or 'as' operators to test whether any particular object implements INotifyPropertyChanged, regardless of the handle provided. It doesn't matter if you expose the collection as an IEnumerable, the Binding will check if the actual instance implements INotifyCollectionChanged. Since the instance is actually an ObservableCollection, it does implement it and the Binding can simply subscribe to the CollectionChanged event. So WPF seems to use relfection to check if the returned object implements INotifiyCollectionChanged and so on..

  • @igorb1548
    @igorb1548 10 หลายเดือนก่อน

    6:35 Can, please, someone explain (or provide a link) why binding to an object that does not implement INotifyPropertyChange could result in memory leaks, especially when the properties are readonly.

  • @andresmoring4538
    @andresmoring4538 3 หลายเดือนก่อน

    Hello i got a problem if i remove startupUri programm starts but it doenst open the window. I did it like you show it, in the class app maybe someone can help

  • @Diegoad1
    @Diegoad1 2 ปีที่แล้ว

    10:30, Why the list is binding in one ViewModel, and the values of the columns comes from another ViewModel?

  • @calebleecoding
    @calebleecoding ปีที่แล้ว

    I've seen both Models and ViewModels implement INotifyPropertyChanged. Is either one the "correct" way or if MVVM flexible in which does?

  • @prashantmanjule
    @prashantmanjule ปีที่แล้ว

    What if we implemented INotifyPropertyChange directly in Models for properties, and for CurrentItem in ViewModel ? why need to create extra glue code?

  • @davidjennings6293
    @davidjennings6293 16 วันที่ผ่านมา

    As you are typing your XAML, I notice that Visual Studio seems to be adjusting the order of the tag attributes as you type them. Is this a setting in Visual Studio, or are you working with an extension?

    • @SingletonSean
      @SingletonSean  16 วันที่ผ่านมา +1

      Yes! I use this:
      th-cam.com/users/shortsFVO5HhUotHE?feature=share

  • @codingdave
    @codingdave 3 ปีที่แล้ว +1

    Hey Sean, great video as always!
    The propchange snippet, does it really allow _lowercase field and Uppercase property automatically? I always failed setting up a snippet to do that. Also looking at yours i do not see the trick that is responsible for it. I would try but i have no PC right here.

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว +2

      Thanks David! I've wondered the same thing about snippets. Unfortunately, I never looked to deep into it, and I'm not sure if it's possible. That said, I am indeed typing both the field and property name separately

    • @codingdave
      @codingdave 3 ปีที่แล้ว

      @@SingletonSean thanks. So do I unfortunately. I know this has been requested years ago but i forget where.

  • @austincascarelli
    @austincascarelli 4 หลายเดือนก่อน

    Maybe someone can clarify this for me, at 15:09 Sean adds a binding setting to UpdateSourceTrigger on PropertyChanged. That seems like a lot of overhead to me, to re-instantiate our MakeReservationViewModel every time a new character is typed. Is this actually OK in practice and what is the reasoning to update the binding so frequently?

    • @LpMitKm
      @LpMitKm 11 วันที่ผ่านมา

      Kinda late, but my guess would be to validate input.
      Like disallowing a certain set of characters to be typed in.

  • @danielschmidt9380
    @danielschmidt9380 2 ปีที่แล้ว

    Why do you repeat all model-properties from type "Reservation" inside of your ReservationViewModel? I think it is not DRY. I do it because datatype-mismatch, so just use an UI-converter for this problem. :-)

  • @confidential5728
    @confidential5728 2 ปีที่แล้ว

    How to refer to names of xaml elements (x:Name) of Views (that are defined under "views" folder for instance) from inside ViewModels??? Because there is no linkage as in the case of ".xaml & .xaml.cs " pairs when creating window classes. Any help appreciated.

  • @MrSK168
    @MrSK168 ปีที่แล้ว

    Hi,
    Do Anyone have idea why my textbox is readonly?
    I'm in the testing point at 14:00 min, and I can't write on the name textbox.
    Does it related to the fact that the textbox is binding?
    How do I solve it?
    P.S.
    So far great tutorial!

    • @MrSK168
      @MrSK168 ปีที่แล้ว

      I have tried this solution:
      But it didn't help

  • @xiaobaibai5871
    @xiaobaibai5871 2 ปีที่แล้ว

    Hi, Hey Sean! I havae a question: on time 4:00 when you propchanged a property, you named the private one and suddenly the public one is also changed, how did you do this? Any Extension or Configuration? Thanks!

  • @TheWolverine1984
    @TheWolverine1984 2 ปีที่แล้ว

    I have a question, this is not strictly about this video, but on the concept as a whole. How do changes in the model propogate to the UI layer? For example, if I'm implementing a counter for 'X days from fatal accidents'. I might have a DaysFromAccidentModel, which will have an int field. Then I'll do a DaysFromAccidentViewModel, to which I'll pass the model. And it will have a property that implements INotifyPropertyChanged that reads the value of the int in DaysFromAccidentModel. And finally I'll have a view DaysFromAccidentView that has a textBlock that binds to the ViewModel's property.
    I understand that if I change the counter in the UI it will trigger the InotifyPropertychanged interface and the change will be reflected in the viewmodel. But how will it be refected in the model itself?
    Also, how a change in the model be reflected in the UI? For example if I reset the counter in code and not from the UI, how will the view model know the value was changed?

    • @SingletonSean
      @SingletonSean  2 ปีที่แล้ว +1

      Hey TheWolverine, this is a good question and something I have questioned in the past.
      For updating the model, you could simply do this directly from the view model or command.
      To get changes from the model, you would want to define events in the model, raise that event in the model whenever the data changes, and then subscribe to that event from the view model so that the view model can get the latest data from the model. Alternatively, you could define a "Store", which is something I introduce later in the series. The Store would act as a wrapper to the model and implement events to raise whenever the model changes. All updates to the model would then go through the Store.
      Let me know if this makes sense or you have any questions! It might be worth watching the video on Stores to get an idea of how they could solve this issue.

    • @TheWolverine1984
      @TheWolverine1984 2 ปีที่แล้ว

      @@SingletonSean Yeah, thanks! This makes sense!

  • @bodzio2k190
    @bodzio2k190 ปีที่แล้ว

    No bloviate, just specifics!

  • @ak-dy7ty
    @ak-dy7ty 3 ปีที่แล้ว

    Hi Sean. Amazing roundup! Thanks for that a lot. Question though: in your setup, the view will not update changes inside the models entities. Only new or removed items is forwarded through the observable collection. How would you tunnel the property changed here? I'd bet you had a less messy implementation at hand than I have done it😉

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว +1

      Thanks a k! That's a good question regarding the ObservableCollections, and I've had to work around this in the past too.
      Ideally, the property changes should go through the view model. Then, you can simply call OnPropertyChanged before forwarding the property setter to the underlying model.
      However, it isn't always feasible so go through the view model. In that case, I would recommend defining an event on the model for when the property changes (possibly implementing INotifyPropertyChanged, but it could really be any event type). Then, the view model could subscribe to the event on the model, and raise PropertyChanged on the view model.

    • @ak-dy7ty
      @ak-dy7ty 3 ปีที่แล้ว

      @@SingletonSean thanks for pointing to events!That means basically that the datamodel will implement INotifyPropertyChanged and acts as a viewmodel ("data"viewmodel)?

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว

      I think that's a good conclusion! Despite the model implementing INotifyPropertyChanged, I usually still prefer to not bind directly to the model (for separation of concerns).

    • @andiwand1119
      @andiwand1119 2 ปีที่แล้ว

      @@SingletonSean I am not sure but it seems there are two camps for this issue..The one is using proxy properties (like you did here) and the other uses the INotifyPropertyChanged in the Models. For a clean MVVM approach I go with camp 1. For simplicity and development I often choose camp 2. Searching for a solution for this problem since I started WPF years ago..

  • @trustingod0
    @trustingod0 4 หลายเดือนก่อน

    Do we have to have the properties on the ReservationViewModel?

    • @Keshi-j4m
      @Keshi-j4m หลายเดือนก่อน +2

      I decided it was worth doing this. Although the part in the video is read-only and the methods in the INotifyPropertyChanged interface are not actually executed, doing so can further ensure the separation of View and Model to ensure the independence of UI logic and business logic. (Although not doing so does not violate MVVM, because for View it is indirectly bound to Model through VM) For example, Username is read-only in Model, but not in ViewModel. We can rewrite it to ensure that the UI logic is not affected as much as possible.

    • @trustingod0
      @trustingod0 หลายเดือนก่อน

      @@Keshi-j4m you can subclass the observable object and keep your model clean

  • @MrSaydo17
    @MrSaydo17 3 ปีที่แล้ว

    I really like using the CallerMemberName attribute so that I don't have to remember to explicitly put in the property name in the setters. I also like to make the base class abstract and the OnPropertyChanged virtual. Its come in handy more than once
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว

      Thanks for the tip Jackson! I've been on some projects that use CallerMemberName, but I never really set it up in my own stuff. I don't find it necessary since my propchange snippet automatically passes the property name to OnPropertyChanged.
      However, it is just one line of code, so it wouldn't hurt to add hahah. On the other hand, I do like the explicitness of having to pass in the property name. CallerMemberName is so magical.

    • @MrSaydo17
      @MrSaydo17 3 ปีที่แล้ว

      @@SingletonSean All completely valid points. I've been really enjoying your MVVM series. It's nice to see the different approaches you use compared to mine. How long have you been working with WPF?

  • @MsQlan
    @MsQlan 2 ปีที่แล้ว

    Hi Sean, a question regarding backing model access in ViewModels.
    I have a Model that is called Sound which is represented in a combobox in the UI through a list of SoundViewModels.
    SoundViewModel has the Sound model in its constructor and uses it to provide data to the view.
    When then selection in the combobox changes it updates its bound property on the backing ViewModel.
    However I need to access the Sound model inside the SoundViewModel to make changes in the domain.
    What would be the best approach here? Add the model as a public property on the SoundViewModel?
    This feels wrong as the Model would then be visible to the View.

    • @SingletonSean
      @SingletonSean  2 ปีที่แล้ว

      Good question MsQlan! I run into this situation quite often. I would solve it similar to how I have the ReservationViewModel here: github.com/SingletonSean/reservoom/blob/master/src/Reservoom/ViewModels/ReservationViewModel.cs
      In this snippet, I have the model as a private field. Then, I expose properties on the view model that dig into the properties on the model. This ensures that the view layer stays decoupled from the model layer, as you mentioned.
      I'm worried about my response here because it sounds like this might be what you're already doing. Let me know if this answers your questions or not!

  • @muamel1
    @muamel1 ปีที่แล้ว

    He's very fast like BMW M5

    • @SingletonSean
      @SingletonSean  ปีที่แล้ว

      I should slow down like my old Honda Civic with 100k+ miles...

  • @humanrayla4785
    @humanrayla4785 2 ปีที่แล้ว

    I was wondering if viewmodelbase should be an abstract class like commandbase will be? If not could you say why?

    • @SingletonSean
      @SingletonSean  2 ปีที่แล้ว

      Hey Human Rayla, I think ViewModelBase could definitely be abstract. The reason CommandBase is abstract is because the Execute method is abstract, so the class needs to be abstract too. For ViewModelBase, there are no abstract methods that derived classes need to implement, so it's acceptable to leave it as non-abstract. Nonetheless, I think it would make sense for ViewModelBase to be abstract because it is an "abstract" concept.

  • @randypenajimenez3893
    @randypenajimenez3893 2 ปีที่แล้ว

    Placing all the view models as properties inside a MainViewModel wich serves as the root view model and works like a singleton is a good aproach?

    • @SingletonSean
      @SingletonSean  2 ปีที่แล้ว +1

      Good question Randy! I wouldn't consider it a good approach in most cases, but that is certainly what I did here for demoing view models. Later in the series, I setup navigation to combat this approach.
      On the other hand, I usually do have a single view model property inside the MainViewModel when I have an application with one page/no navigation.

  • @ahmedmahjoub2730
    @ahmedmahjoub2730 2 ปีที่แล้ว

    Thanks for the tutorials, very clear und teachful! I'm implementing a chess game using WPF, for the drag and drop of the pieces I need to implement the method that will handle the event in the xaml.cs file of the view, and I have to update the gamestate at the same time. But how do I access the gamestate (Model) if it is a bad practice to have a Datacontext of the Model in the controller (xaml.cs). Thanks for any response in advance

    • @SingletonSean
      @SingletonSean  2 ปีที่แล้ว

      Good question Ahmed! I've run into this issue in other drag drop projects I've worked on. Check out this series: WPF Drag Drop
      th-cam.com/play/PLA8ZIAm2I03gLDtS1V8CwMYgyQa1U5QYw.html
      In part 2, I show how to update view models from drag and drop. Hope this is helpful!

    • @ahmedmahjoub2730
      @ahmedmahjoub2730 2 ปีที่แล้ว

      @@SingletonSean Thanks a lot.

  • @shahinlarki9822
    @shahinlarki9822 3 ปีที่แล้ว +1

    Hi, I love your tutorials. I live in Iran and due to sanctions I can not be a member of your support channel, so some of your videos can not be played😐😐😐

    • @SingletonSean
      @SingletonSean  3 ปีที่แล้ว

      Sorry to hear that Shahin! Hopefully TH-cam's legal team is working on mitigating this issue. No worries though, all of my member-only videos will eventually be released publicly. Regardless of being a member or not, I appreciate your support of the channel Shahin!

    • @shahinlarki9822
      @shahinlarki9822 3 ปีที่แล้ว

      @@SingletonSean Thank you. The good news is that the videos are being released to the public. I hope you continue to work with the same quality❤️

  • @jpeike1314
    @jpeike1314 2 ปีที่แล้ว

    got to 14:39 and the window is completely blank, I literally have no idea what's wrong help pls

    • @jpeike1314
      @jpeike1314 2 ปีที่แล้ว

      No matter what color I make backgrounds, no matter what I do, White screen.

    • @jpeike1314
      @jpeike1314 2 ปีที่แล้ว

      Each View shows up in preview, but when I click run I have an empty window.

    • @Anequit
      @Anequit 2 ปีที่แล้ว

      @@jpeike1314 are you setting the view in the main window?

  • @ivandrofly
    @ivandrofly ปีที่แล้ว

    14:34 Find Find error in Visual Studio

  • @danwhizard
    @danwhizard 2 ปีที่แล้ว

    Mechanics question here - at th-cam.com/video/2FPFgW0xVB0/w-d-xo.html you set up the public reservationViewModel properties with the '=>' operator since the _reservation object is readonly (you don't need to set). However, when I do this, I have to use "Mode=OneWay" in my binding on the view, or I get this: A TwoWay or OneWayToSource binding cannot work on the read-only property
    How is your code working without the "Mode=OneWay" attribute in your XAML?

  • @johanmilterjakobsen1627
    @johanmilterjakobsen1627 ปีที่แล้ว

    Youre really good. But its going too fast.

  • @maanalshraky1
    @maanalshraky1 ปีที่แล้ว

    Thanks for the effort but on the other hand you are speaking no stop like the gamers, and not trying to explain it's just a show-off. Frankly, it will be more helpful if you keep the narration regular.

  • @scorpio0609
    @scorpio0609 2 ปีที่แล้ว

    When manually adding the reservations in the ReservationListingViewModel for testing and demo purposes we are bypassing the the conflict handler.
    _reservations = new ObservableCollection();
    _reservations.Add(new ReservationViewModel(new Reservation(new RoomID(1, 3), "Bob", DateTime.Now, DateTime.Now.AddDays(3))));
    _reservations.Add(new ReservationViewModel(new Reservation(new RoomID(1, 3), "John", DateTime.Now, DateTime.Now.AddDays(3))));
    You can add 2 conflicting reservations and error won't be raised.
    In order to test the Conflict raising error
    I would suggest to do it in one of 2 ways. For both of them we can create an instance of ReservationBook and add the reservations to it. This way we will fire the Conflict if such exists
    private readonly ReservationBook _reservationBook;
    _reservationBook = new ReservationBook();
    _reservationBook.AddReservation(new Reservation(new RoomID(1, 3), "John", DateTime.Now, DateTime.Now.AddDays(1)));
    _reservationBook.AddReservation(new Reservation(new RoomID(1, 3), "Bob", DateTime.Now.AddDays(2), DateTime.Now.AddDays(5)));
    _reservationBook.AddReservation(new Reservation(new RoomID(3, 2), "Maria", DateTime.Now, DateTime.Now.AddDays(2)));
    _reservationBook.AddReservation(new Reservation(new RoomID(2, 3), "Lorain", DateTime.Now, DateTime.Now.AddDays(2)));
    1. First way -
    private readonly ObservableCollection _reservations;
    _reservations = new ObservableCollection();
    foreach (var reservation in _reservationBook.GetAllReservations())
    _reservations.Add(new ReservationViewModel(reservation));
    2.Second way - similar but to use IEnumerable
    private readonly IEnumerable _reservations;
    _reservations = _reservationBook.GetAllReservations().Select(x => new ReservationViewModel(x));

  • @jennibgmailcom
    @jennibgmailcom 2 ปีที่แล้ว +1

    Fantastic but please give us a second to read what you typed before the edit.