WPF Nested User Controls and MVVM (esp. Caliburn.Micro - wpf

I’m taking a lot of worry selecting an MVVM framework to convert to. One of the major considerations is support for User Controls and nested user controls as my main page today has a user control that contains nested user controls.
The author of Catel highlights lack of support for nested user contorls as a major disadvantage of other platforms (inc. Caliburn.Micro)
So my question is: Doesn't Caliburn.Micro support nested user controls?

Caliburn.Micro doesn't place any restrictions on the types of mechanisms you use for developing your user interface. It isn't a requirement to use Caliburn.Micro's conventions, you can still be explicit with your bindings when required.
If you are using user controls to reuse user interface code during view composition, then Caliburn.Micro provides an alternative technique for this too, using view model properties and ContentControls.
See here for an example.

Related

How to architect graphically-intensive Silverlight app using MVVM?

I'd like to create a Silverlight app using WCF Ria Services and the MVVM design pattern.
The main page of the app will consist of a "shell" and a large number (10s or 100s) of objects of different look (shape/size/properties) linked to each other (forming a sort of graph).
These items need to be mouse-draggable and their current position/state needs to be saved to the back-end database.
I feel that the best way to achieve this would be to have a small ViewModel and View for each item displayed, put all the important properties into the ViewModel and then somehow display all these Views in the main "shell".
However, I don't know how exactly this could be achieved. I considered using MVVM Light, but didn't find any example that would show something similar.
Can anybody point me to some examples or ideas about how this could be done?
"When all you have is a hammer, everything looks like a nail" :)
MVVM is not designed to manage graphic intensive situation like the one you describe. It is a glue for stitching together high-level concepts in a flexible manner. With MVVM you are adding overheads that will impact performance (e.g. binding uses reflection behind the scenes). The more objects involved, the greater the impact.
The best starting point I can suggest is to imagine what you need from a 3rd party control (e.g. a custom control/container) and, if one does not actually exist already, build it as if it were a third party custom control.
You will find in practice that custom controls are seldom based on MVVM, for performance reasons if not just because "they often don't need it". They may well expose MVVM compatible properties for the external interface, but not for the low-level internals.
MVVM is a relatively high-level technique. Do not feel you have to implement it on everything.
Following MVVM do the next:
Model - create model object which will be responsible for fetching and persistence coordinates of the shapes on the screen;
View Model - one view model which will initiate fetching and persistance model objects;
View - in your case, it's a place where you do most of your work. Create custom control based on ItemsControl with Canvas panel. Custom control should pass collection of the model objects in ItemsSource, allow to drag and drop containers and call the view model command when user drops container in some place
Have a look at the Telerik controls, specifically radTileView, this seems to have the functionality that your looking for. They also have a persistance framework that should allow you to save the position of the tiles back to you database.

User controls vs Custom Controls Silverliht

For developing a dashboard which will have many different widgets available, graphs, grids, etc, is a user control the best thing to use or a custom control?
I am a bit confused about the best situations to use each of them in
This relates to Silverlight 5
Paul
The key difference between user controls and custom controls is that custom controls can be re-templated, i.e. you can completely change their visuals by supplying a different template. If you do not need to do this in your application, I would recommend using user-controls as a simple alternative.
I have written a blog post about how to create them here:
A Simple Pattern for Creating Re-useable UserControls in WPF / Silverlight

ObserverableCollection UI pattern in WinForms

In many ways I think of using the MVC pattern in WinForms, but I'd like to know if it's possible to bind controls with objects using the ObservableCollection type? If it's purely for WPF, what other alternatives are out there?
To put it into perspective, we're building a system which has business logic that I'd like to control the UI with, instead of making customizations for each requirement or workflow on the UI itself. We have around a few hundred potential forms which I'd like to start designing with the pattern in mind.
We're also building web interfaces for most of the processes, but in reality they're just watered-down versions of the Forms. If I can use the same framework which I can just bind to on the web form that would be awesome.
Thanks
What ObservableCollection does is that it implements INotifyPropertyChange and each control in WPF has the possibility to listen for it's bound data to raise the event from INotifyPropertyChange. You can read more here about why you can't use ObservableCollection they way you want to in WinForms.
Another way is to use the Model-View-Presenter pattern:
This pattern can also be used in ASP.NET.
There's an MSDN Magazine Article on: "Better Web Forms with the MVP Pattern" that I think you should look into. And here is an introduction to how you use MVP-pattern in asp.net.

How MVVM with DataTemplateSelector is portable from Silverlight to Flex?

I asked a question here about MVVM In MVVM there can be only one View for each one View Model?
Answer would be to use DataTemplateSelector to get multiple views. Now let's say I need to port to flex. Does Flex have the same paradigm as DataTemplateSelector?
Since Silverlight claims that it is close to Flex then I'd like to see proofs :)
Specifically, there is no "DataTemplateSelector". That is not surprising, though, because they are different stacks... (They ARE extremely similar to each other with regards to feature parity and developer paradigm) In Flex, there is the concept of skins, which are very similar to templates. There is also the concept of item renderers, which closely resemble data templates in repeated views (List, DataGroup, DropDownList, ComboBox, DataGrid, etc)
In the case of item renderers (most likely what you are talking about), the components have an optional itemRendererFunction property which is a function that decides which item renderer to use. It allows for extremely dynamic views to be slapped on top of Presentation Models (they are not called View Models in Flex... they use the original name of Presentation Model... not sure why Silverlight ever changed it to MVVM... I digress).
As for skins on all other (Spark-based) components, you can change the skins at runtime using .setStyle('skinClass', TheSkin)
In addition, you can use IoC containers to glue together Presentation Models with any view. This is actually very easy.
Along the same lines, I once built a very tiny view mapping engine that lets you register views against types and the data binding happens automatically. A lot like the RegionManager in Prism for Silverlight.
If you are interested in how Presentation Model fits within Flex, I have written two articles about the topic:
MVVM vs Presentation Model
Presentation Model for using in Multiple Screens
The second link will have a follow-up posted on Tuesday that describes how you use multiple views on top of the same Presentation Model.
So, yes. There are several solutions to achieve what you want to achieve. None of them are direct, because they are different stacks, but the functionality is certainly there.

MVVM/Presentation Model With WinForms

I'm currently working on a brownfield application, it's written with winforms,
as a preparation to use WPF in a later version, out team plans to at least use the
MVVM/Presentation model, and bind it against winforms...
I've explored the subject, including the posts in this site (which i love very much),
when boiled down, the main advantage of wpf are :
binding controls to properties in xaml.
binding commands to command objects in the viewmodel.
the first feature is easy to implement (in code), or with a generic control binder, which binds all the controls in the form.
the second feature is a little harder to implement, but if you inherit from all your controls and add a command property (which is triggered by an internal event such as click), which is binded to a command instance in the ViewModel.
The challenges I'm currently aware of are :
implementing a commandmanager, (which will trigger the CanInvoke method of the commands as necessery.
winforms only supports one level of databinding : datasource, datamember, wpf is much more flexible.
am i missing any other major features that winforms lacks in comparison with wpf, when attempting to implement this design pattern?
i sure many of you will recommend some sort of MVP pattern, but MVVM/Presentation model is the way to go for me, because I'll want future WPF support.
Thanks in advance,
Erik.
Please take a look at Update Controls .NET. It is an open-source library for Winforms, WPF, and Silverlight that keeps controls up to date as data changes. You can start using it now for Winforms, and then transition over to WPF without changing your Data Model or View Model code.
Unfortunately, it does not solve the Winforms command binding problem. Your button click events will not port from Winforms to WPF. But it does take care of the data binding problem.
You might find the WAF Windows Forms Adapter interesting. It shows how to apply the Model-View-ViewModel (MVVM) Pattern in a Windows Forms application. The Adapter implementation provides a solution for the missing Command support in Windows Forms.

Resources