how to execute events in mvvm pattern for silverlight - c#

Can anyone provide a short example of how to execute an event within the mvvm pattern for silverlight? In reading I have seen references to where silverlight does not support commanding? If that is the case how then what is the most common practice to initate methods in the mvvm pattern? Is a third party framework need or can this be accomplished using routed events? A simple example would be great... say a button wihtin the xaml and then within a viewmodel class the method to open an alert window of change the text of a textblock? I'd appreciate any insight as to what the most common approach is for initiating an event( mouse click events etc) and how these methods could be called.
thanks in advance

Though there isn't an implementation on Silverlight, the ICommand interface is present in the framework. You should take a look at the DelegateCommand class in Prism.

Related

Embed Windows.Form in WPF application

I was wondering, is there a consequence to embed a Windows.Form element in a WPF application ?
I don't really know the difference between both architectures, but mixing them can have negative impacts ?
There are always consequences with such choices.
Mainly winform doesn't support wpf event mechanism for bubbling event and dependency properties, you have to wrap it up if you want to use some binding and follow the MVVM pattern.
Besides, it will not be a part of the visual tree if I remember well. It will create an other form over the form of your application, i.e. an other window handle...
Not impossible, but You got to wondering yourself If it is worth it.

Does Prism provide a mechanism for commands that close a window?

I believe that I saw somewhere that Prism provides a WPF mechanism for implementing ICommand that closes a window. I've been looking over the documentation but it's overwhelming and I can't seem to pinpoint anything about this (if it even exists). Does Prism have MVVM helpers for closing, or even creating, windows via view model command binding?
I do see that you can do it a more "manual" way, without Prism, but Prism does provide helpers for other similar tasks.
No, Prism doesn't provide any helpers for closing a Window. This can be done with standard MVVM techniques, and there is nothing special needed to accomplish this..

Creating custom event in windows phone

I have such usecase:
In my application some instances need to fire event, that they have been changes. But, I dont want to keep references to instances that need to be changed, so I would like to send event and somehow listen it in some places, but how to do it in C# in windows phone?
You're looking for the EventAggregator. There are a few toolkits that you can build upon like GalaSoft's MVVM Light and Caliburn Micro. You can find a good example of this at http://www.mindscapehq.com/blog/index.php/2012/02/01/caliburn-micro-part-4-the-event-aggregator/.
The basic gist of it is to inject an EventAggregator into your ViewModel. This ViewModel would Publish an event. Other ViewModels would subscribe to this event.

WF, WPF and Silverlight common event handlers

I have a controller that needs to capture some events(MouseMove, MouseDown, KeyDown, ...) raised by a control(this control could be WinForms, WPF or Silverlight).
Is there a way to implement such a general controller?
*added by ChrisBD *
Background:
I have a MVC application and I have a controller(GeneralController) that has acces to IGeneralControl. This IGeneralControl will be implemented by a WPF, WF and Silverlight specific control(WFControl, WPFControl, SilverlightControl). What I want to achieve is to be able to add my code to the delegates of the control at the level of the GeneralController, without the need to implemet WFController, WPFController and SilverlightController
I'm no forms expert but I'm skepical that you can do this with some works for all GeneralController. WPF/Silverlight use a very different event model, using staticly declared routed events.
I think you'd need to implement your WFController and a separate WPF/Silverlight controller.

General WPF Application

Am just creating myself a WPF application, like outlook. am having all forms seperately. I just want one main window and and am haivng navigation pane in left side. when ever i click items in pane, i just want to load corresponding form to the main window in right container. How i can do this?
Use a design pattern like MVP or MVVM..
Also you probably want to use the Command pattern which will benefit the maintainability of your UI related commands.
Tutorials:
WPF Patterns
This tutorial should get you started with these patterns. Paul Stovell shows how to implement MVP and MVVM and displays strenghts and weaknesses of each pattern.
OutlookBar:
This link should get you started with the UI part of your challenge. It shows how to use such a control and implement the Command pattern.
HTH

Categories