I've written 1 WPF app. A pretty simple app. It works great and is being used heavily as a LOB app today. Now I'm going to start work on a major re-write of an old VB6 app, and will make it into a WPF app as well. When working on the first app I learned of the INotifyPropertyChanged interface, and how vital it is to WPF/Silverlight data binding. My concern, now, is that quite some time ago I wrote a WCF service which is meant to replace the old middle-tier component I wrote in VB6 many years ago, for the old VB6 app. The WCF service I wrote returns ADO.NET datasets, because honestly I've been working with those for years and am comfortable with them. However, now that I'm beginning to work on this new app, I'm very concerned about my WCF service, since ADO.NET datasets don't implement the INotifyPropertyChanged interface.
So I've started looking at other things. Right now I'm looking at Entity Framework. I'm using Julia Lerman's book, "Programming Entity Framework: Second Edition", and it really looks promising. I've working through her example of a WPF app, which uses a EDM assembly she wrote in a previous chapter. Including references to the assemblies gives me CollectionViewSource's, and at least to me, it appears as though they act much the same way that the INotifyPropertyChanged interface does.
So my question is this: does the CollectionViewSource class implement the INotifyPropertyChanged interface? I've tried looking at the MSDN documentation, and it doesn't say so, directly, but I'm wondering if the DependencyObject class CollectionViewSource inherits from either duplicates the same functionality as the INotifyPropertyChanged interface, or does CollectionViewSource implement it?
You'll notice the MSDN doc on CollectionViewSource contains this as the class declaration:
Public Class CollectionViewSource _
Inherits DependencyObject _
Implements ISupportInitialize, IWeakEventListener
Neither it nor its base classes implement INotifyPropertyChanged. When you bind to the View of the CollectionViewSource, you must call its Refresh() method yourself when the underlying collection changes. If you change properties (such as sorting and grouping) of the CVS, Refresh is called automatically.
just to mention a little detail to Rod answer:
when adding or removing an item to collection, the items goes through any filter, grouping, sorting, etc.
But when a property of an existing item changes, then, you have to handle that by yourself to update filters, grouping, etc.
At this point, the solution of the Refresh() works BUT, can bring very bad user's experience since the whole collection get refreshed.
One solution is to simulate an remove/insert of the item. See my post fore more details.
Related
Despite I google-d for some time I couldn't find any of the Model-View-XYZ framework implementations for server-side Blazor, that is Razor Components (XYZ stand for any of the following: Controller, Presenter, ViewModel).
If anyone knows of such an implementation, no matter in what stage of development it is, please let me know. Thanks a lot in advance.
EDIT: The question is if someone has encountered, or takes part in development of such a framework.
The question is absolutely simple - has someone encountered some info on the Internet about such a framework targeting Razor Components (aka server-side Blazor), since I haven't so far.
I'm not 100% sure what your question is so I'm taking a stab at what I think you're asking.
It's important to understand that Blazor is not opinionated about how you choose to structure your code. The team have been very clear that they will not force any patterns on developers. This means that you are free to structure your code how you feel is best.
If you're interested in MVVM for example, Jeremy Likness has a great blog post covering using this pattern in Blazor apps. But if you are looking for official docs covering this then you're out of luck.
Hope this helps, if not please clarify what it is you're looking for.
Blazor itself is an MVVM framework. The HTML in your Razor Component is your View. The #functions section is your ViewModel and you can use POCO classes for your Models.
I released HanumanInstitute.MvvmDialogs as a platform-agnostic solution to display dialogs. It's currently implemented for WPF and Avalonia.
Blazor support could easily be added by copying from the Avalonia branch. If someone wants to take on that task.
After reading about it I implemented this MVVM design for Blazor Webassembly + WebApi app. A ViewModel is injected as transient into the View and the View calls the ViewModel's Initialize() which causes updates to ViewModel's properties which fires property-update events which are handled by the View to update the presentation state. The ViewModel also handles user actions that come from the View. ResourceApi is injected as singleton into the ViewModel which subscribes to resource-updated events. Model caching can be implemented at the ResourceApi layer. An action that updates a resource raises a resource-updated event which causes the ViewModel to reload the data and in turn raise its own property-changed event which is picked up by the View to update the presentation using binding.
I am new to MvvmCross and Xamarin. I have been looking into this for some time now and I am trying to find what is the best way to send some data from ViewModel B to ViewModel A. Meaning that ViewModel A is responsible for showing ViewModel B. It's fairly straight forward on how to send data to a ViewModel when launching it, however there is no clearly defined tutorial that I have come across that is showcasing how to send the data back to the starting ViewModel on finishing.
I have come across Event Aggregators like MvvmCross.Messenger that seems to be an ideal candidate. However for an Android project I am not sure if that is a good choice due to Android Activity life cycle methods.
Any help on this would be very well appreciated. Thank you.
The Messenger is the right way to do it, it has been covered in another stack overflow question. There is even a sample code you can toy with.
The gist is that both ViewModel receive a (possibly singleton) Messenger, and when ViewModelB wants to let ViewModelA it needs to reload its data, ViewModelB sends a message through the messenger.
Internally Messenger uses a WeakReference to ensure garbage collection can still go on (check this post for more information)
It sounds like what you want to do is to show a VM for a particular result to be returned to the "parent" VM. This is baked into Android with StartActivityForResult, but needs some hacking to implement with MvvmCross.
Greg Shackles wrote a tutorial on how this can be accomplished. Further discussion here. It's a better fit for the Android activity flow than using the messenger, if I understand your usecase correctly.
I am evaluating Telerik Test Studio (http://www.telerik.com/automated-testing-tools) as a web regression tool and looking for a how-to on setting up and using of a Page Object Model environment like is possible in Selenium.
http://code.google.com/p/selenium/wiki/PageObjects
Their documentation is focused on record/playback which is very brittle, and my google searches haven't turned up relevant links.
I would say, you really need not implement a Page-Object model if you are using Telerik Test Studio(TTS). TTS comes with its own AUT Object manager which is of above average quality and does a decent enough job. However, if you must go for a Page-Object implementation; here are some guidelines:
You must install VS 2008 or upwards because you really don't want to do a lot of coding in the TTS standalone.
In the solution structure, add a class file for each of the pages that you are going to work with.
Implement the methods that you want to execute on the page elements as Public methods in the corresponding class.
Declare the properties of the pages as variables in the appropriate class.
In the Test class, instantiate the relevant page classes.
While it is true that there is no framework support as such for implementing the page-object model in TTS, the basic essence is easy to replicate. Beyond that, it is up to you to extend the approach to higher levels.
VS2010 Pro + SqlServer Express.
Having been dropped into ASP.NET MVC 3 with no guidance but the web (2 books on order), I can't even get off the ground.
The MVC itself I get. Not a problem.
PHP, Ruby, and even ghastly WebForms firmly tucked into my toolbelt, with a long history of C++ QT client-server development before that.
Tying ASP.NET MVC 3 to a database using EF4 ORM is killing me.
The goals:
Use database modeled by DBA. I can specify all naming conventions, but code first is not an option!
Import to EDMX. This will be regularly updated using VS tools from the DBA's DB, never edited directly.
Generate partial classes from EDMX, for use as model. This will regularly be updated using VS tools, never edited directly.
Use 'buddy' to extend above model class with code as the Controllers/Views need.
Intuitively use the resulting model, pass it to the view, retrieve posts into it for insert/save, etc...
I've seen and read so many blogs, forum posts, walkthroughs, and stack overflow posts regarding this very use case.
I even tried riding the magic unicorn, followed by the latest 4.2beta1 with DbContext generators.
But can't get off the ground.
I follow instructions, but just not understanding how to do anything with it.
What conventions does the 'buddy' require (if any)? How do I use it? How do I get data with it? How do I write data?
Every example looks different. MVC guides are always focused on the UI side. EF guides don't cover usage in the MVC.
These are basic questions, and I'm feeling like the most incompetent idiot in the WWW right now.
Is anyone out there currently using MVC3 & EF4.x in the way I describe above?
This video is a good starting resource. Its a video of a guy creating an app from scratch that uses entity and a sql database (though he makes the db in the video, its still good for seeing some basics in action). You can see how he pulls data from the database, displays it on the page, and saves changes back to the database.
The first question I would ask is why are you stuck on using EF as an ORM or even insisting an ORM at all? I'd choose tools to suit the job here, especially given the constraints of the data layer.
Buddy classes were a concept invented in a day when the main .NET ORMs had no code-first option as ORM-encumbered class instances really don't behave well under things like model binding. Nevermind you could not decorate them with the DataAnnotations one used to indicate fields were required. Typically, the technical requirement is to use [MetadataType] attributes to tie your buddies to your models and perhaps something like AutoMapper to map data to and fro.
All that said, as a guy who has a few apps with lots of buddies and lots of automapping going on, you might want to think otherwise -- it is a bit of a maintenance nightmare. I'm living it.
There are some really good getting-started videos and tutorials right on ASP.NET MVC's site. The "Model (Data)" section is Entity Framework focused and touches on hot/trending topics like Repositories and Units Of Work.
In an WP app which approach is better.
From the .xaml page, call a method of another class (pass the delegate of a .xaml.cs callback Method ) which makes some request to server , receives data and when requests complete calls the .xaml.cs page method. and in call back method we get data and bind the data with a control (ListBox).
Bind the List box with an ObservableCollection object of MainViewModel class. and change the bounded object from the MainViewModel. All the calls to requests to server are made in MainViewModel class.
I vote for the option 2. Event the project templates (Eg. Databound application template for Windows Phone 7) gives you the MainViewModel and binds a Listbox to an ObservableCollection in that class.
The MVVC approach gives you a lot more flexibility, your UI is totally separated from the logic. ALl your UI needs to know is that it is bound to an ObservableCollection and it doesn't need to know how that collection is filled.
I think you should use the second approach which allows you to create loosely-coupled applications. The big advantages of such applications are:
separation of concerns: different subsystems/layers are independent
unit testing is simple
refactoring is easier
increase ability to code reuse
...
Regarding WP7, you can read my article which shows how to code using this approach:
a framework for building of WP7 application