Тёмный

View Models - WPF MVVM TUTORIAL #3 

SingletonSean
Подписаться 22 тыс.
Просмотров 81 тыс.
50% 1

Learn about the view model layer of MVVM, which provides the view with data to display and commands to execute. View models should be simple and give the view exactly what it needs.
In this series, I demonstrate all the key components of a WPF MVVM application. This series will lay the foundations for building your own application.
TIMESTAMPS:
0:00 - Introduction
0:30 - Implementing a ViewModelBase (INotifyPropertyChanged)
2:02 - Scaffolding View Models
2:30 - Implementing the MakeReservationViewModel
5:30 - Implementing the ReservationListingViewModel
11:29 - Implementing the MainViewModel
12:47 - Setting Up the MainWindow
14:31 - Testing and Fixing Issues
17:34 - Conclusion
PROPERTY CHANGED SNIPPET: singletonsean.s3.amazonaws.co...
SOURCE CODE: github.com/SingletonSean/rese...
💎 Become a Member: / @singletonsean
🏠 Discord: / discord
🐤 Twitter: / singletonsean_
🏆 Donate: www.paypal.com/donate?hosted_...
✉️ Email: youtube@singletonsean.com

Наука

Опубликовано:

 

30 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 108   
@GetMoGaming
@GetMoGaming Месяц назад
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 года назад
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 :)
@ronaldnelson9385
@ronaldnelson9385 2 года назад
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!
@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. 🙏
@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!
@getsuha
@getsuha Год назад
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 Год назад
Fantastic Suhasis, glad this has been helpful and has a good pace!
@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
@gutibokeron
@gutibokeron Год назад
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!
@AlexReflex
@AlexReflex Год назад
I am (also) a C# developer, but never used WPF before. Great video series. Always rechecking your videos, when I need something :D
@dasfahrer8187
@dasfahrer8187 2 года назад
Propchange snippet is so useful. Thanks for that.
@SingletonSean
@SingletonSean 2 года назад
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?
@polarisnation201
@polarisnation201 2 года назад
I'm glad to hear that a new video has been uploaded.
@SingletonSean
@SingletonSean 2 года назад
And more on the way Polaris :)
@dimime1
@dimime1 2 года назад
The best MVVM tutorial on RU-vid!
@SingletonSean
@SingletonSean 2 года назад
Woohoo, thanks Dmitry!
@mrt7948
@mrt7948 2 года назад
he is a master in software. Respect.
@HDunno
@HDunno 4 месяца назад
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 7 месяцев назад
Better than all the paid courses I know. Thank you from the bottom of my one braincell!
@issamdak5065
@issamdak5065 Год назад
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
@yangthomas5064
@yangthomas5064 Год назад
amazing tutorial
@Anequit
@Anequit 2 года назад
Wow thank you for that snippet lol such a timesaver
@SingletonSean
@SingletonSean 2 года назад
It really is hahahah, I feel so slow without it. Glad it's helped, Anequit!
@franakciuleney280
@franakciuleney280 Год назад
Very nice!
@MadBiker88y
@MadBiker88y 2 года назад
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.
@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.
@bearzal2234
@bearzal2234 Год назад
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?
@domenicoboassi282
@domenicoboassi282 2 года назад
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 года назад
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?
@fedorpinega2507
@fedorpinega2507 Год назад
Thanks for video! Sounds funny on 0.5 speed)
@codingdave
@codingdave 2 года назад
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 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 2 года назад
@@SingletonSean thanks. So do I unfortunately. I know this has been requested years ago but i forget where.
@NoAlias536
@NoAlias536 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 7 месяцев назад
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,
@Jeremygrmn
@Jeremygrmn 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 2 года назад
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 2 года назад
@@SingletonSean What if we wanted to be able to update those? Just add the setter with OnPropertyChanged event?
@SingletonSean
@SingletonSean 2 года назад
@MegaGnads Correcto!
@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!
@ak-dy7ty
@ak-dy7ty 2 года назад
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 2 года назад
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 2 года назад
@@SingletonSean thanks for pointing to events!That means basically that the datamodel will implement INotifyPropertyChanged and acts as a viewmodel ("data"viewmodel)?
@SingletonSean
@SingletonSean 2 года назад
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..
@nohopestage
@nohopestage 2 года назад
Great one. I like the way you pronounce "item" haha
@SingletonSean
@SingletonSean 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.
@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!
@ivandrofly
@ivandrofly 11 месяцев назад
6:40 - Why binding to a property that doesn't implement INotifyOnPropertyChanged can cause memory leaks?
@angelotrivelli
@angelotrivelli 2 года назад
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 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 2 года назад
@@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 2 года назад
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 года назад
@@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..
@MagoMakes
@MagoMakes 2 года назад
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 4 месяца назад
Pause the video.
@trustingod0
@trustingod0 Месяц назад
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?
@trustingod0
@trustingod0 Месяц назад
Do we have to have the properties on the ReservationViewModel?
@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.
@calebleecoding
@calebleecoding 9 месяцев назад
I've seen both Models and ViewModels implement INotifyPropertyChanged. Is either one the "correct" way or if MVVM flexible in which does?
@TheWolverine1984
@TheWolverine1984 Год назад
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 Год назад
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 Год назад
@@SingletonSean Yeah, thanks! This makes sense!
@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.
@austincascarelli
@austincascarelli Месяц назад
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?
@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 года назад
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.
@MrSaydo17
@MrSaydo17 2 года назад
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 2 года назад
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 2 года назад
@@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?
@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 ru-vid.com/group/PLA8ZIAm2I03gLDtS1V8CwMYgyQa1U5QYw 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.
@Diegoad1
@Diegoad1 Год назад
10:30, Why the list is binding in one ViewModel, and the values of the columns comes from another ViewModel?
@prashantmanjule
@prashantmanjule Год назад
What if we implemented INotifyPropertyChange directly in Models for properties, and for CurrentItem in ViewModel ? why need to create extra glue code?
@igorb1548
@igorb1548 7 месяцев назад
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.
@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!
@andresmoring4538
@andresmoring4538 10 дней назад
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
@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
@snr2196
@snr2196 Год назад
Why don't you bind View and ViewModels with the TwoWay binding instead of using INotifyChange ?
@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. :-)
@bodzio2k190
@bodzio2k190 Год назад
No bloviate, just specifics!
@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 11 месяцев назад
14:34 Find Find error in Visual Studio
@muamel1
@muamel1 10 месяцев назад
He's very fast like BMW M5
@SingletonSean
@SingletonSean 10 месяцев назад
I should slow down like my old Honda Civic with 100k+ miles...
@danwhizard
@danwhizard 2 года назад
Mechanics question here - at ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-2FPFgW0xVB0.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?
@shahinlarki9822
@shahinlarki9822 2 года назад
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 2 года назад
Sorry to hear that Shahin! Hopefully RU-vid'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 2 года назад
@@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❤️
@jennibgmailcom
@jennibgmailcom 2 года назад
Fantastic but please give us a second to read what you typed before the edit.
@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 Год назад
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));
Далее
Commands - WPF MVVM TUTORIAL #4
13:28
Просмотров 61 тыс.
Models - WPF MVVM TUTORIAL #1
15:21
Просмотров 193 тыс.
Is LEARNING WPF still WORTH it in 2023?
10:59
Просмотров 40 тыс.
Views - WPF MVVM TUTORIAL #2
17:43
Просмотров 74 тыс.
Modern Graphical User Interfaces in Python
11:12
Просмотров 1,4 млн
The Basics of Data Binding in WPF
20:53
Просмотров 35 тыс.
WPF in C# with MVVM using Caliburn Micro
1:23:30
Просмотров 360 тыс.