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.
Related
I have a Xamarin app. (Only) for the UWP app I need access to the mouse events (PointerMoved- / PointerEntered / PointerPressed-Events).
Until now my entire codebase is shared code.
Can somebody help me with forwarding the mouse events to the shared Code base? I googled a lot and nearly all answers either suggest a paid libary called "MR.Gestures" or say that it is not possible to recieve mouse Events (like this one I am not able to implement MouseUp, MouseDown and mouseMove Events in Xamarin Mobile applications). Sometimes GestureRecogniser are mentioned, but they Arent extensible, so how are they supposed to help?
Is there really no way to recieve mouse Events in xamarin?
You can do this. However it is a very extensive work to the level that you might consider to write your app in the native UWP XAML and share some C# code with the Xamarin project instead.
The way would be to extend each control that you are going to use (yes every single control that needs this effect), add to it those events and then write the UWP custom renderers that would invoke those events and then replace all controls in your XAML with those controls.
As said this may turn to be quite extensive work, but that's how it can be done.
Also if you don't need those events but just some visual effects on those events it may be possible to cut on this work by writing a custom XAML styles for those controls in app.xaml in the UWP project.
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.
SCENARIO
I decided to work on WPF technology for my new application. This application has to be called on Menu click from a WinForms window. So I created a WPF UserControl Library and integrate it to display in parent WinForms Form using Element Host.
My Application
It contains 3 child usercontrols which are encapsulated inside another usercontrol with tabContent Control. I prefered this approach as firing events from Child UserControl and handling in WinForms (subscribing events) seemed painful.
My Question
Now facing the same painful task of accessing UserControl elements inside Winforms where I have created Data Manager class for proper project structuring reasons (UserControl should not contain Data Manager class-UI). Please guide me as to how to structure my project/how to subscribe events/access WPFUserControl elements inside WPF.
Take a look at the Messenger class of MVVM Light Toolkit (can also be used standalone). It helps decoupling your controls. The messenger works with a publish/subscribe pattern. Your WPF UserControls can publish objects, the WinForms Host can listen on those notifications. The exchanged messages (objects) are best placed in separate assembly, as they define the shared contract between WPF UC-library and WinForms application.
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.
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.