How to hook ActiveX control into events/changes into my viewmodel? - mvvm

I've added WindowsMediaPlayer ActiveX to my WPF/MVVM application. Now I need the control to react to changes happening in the viewmodel (most importantly updating URL when the current selection in my collection changes). Based on Walkthrough: Hosting an ActiveX Control in WPF I have the following in my Loaded event:
// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();
// Create the ActiveX control.
AxWMPLib.AxWindowsMediaPlayer axWmp = new AxWMPLib.AxWindowsMediaPlayer();
// Assign the ActiveX control as the host control's child.
host.Child = axWmp;
// Add the interop host control to the Grid
// control's collection of child controls.
this.pnlMediaPlayer.Children.Add(host);
Question is - how do I update the axWMP.URL control property on a property change in my viewmodel?

Ok, used Windows.Forms.Binding:
axWmp.DataBindings.Add(new System.Windows.Forms.Binding("URL",(DisplayViewModel)this.DataContext,"Source"));

Related

In Kendo MVVM, stop binding at child container

The kendo docs for kendo.bind state that it will automatically traverse all descendents. I'm creating a composite UI for a microservice backend and I have separate VM's for each component, but I also want to bind to the page containing all of the components. When I bind to the page, it automatically tries to bind to all of the components on the page when I only want to bind to one or two elements in the same page container. This article talks about a way to stop Knockout from binding child elements:
http://www.knockmeout.net/2012/05/quick-tip-skip-binding.html
Is there a way to accomplish this with Kendo?
I just looked through the source code and found (in version 2016.1.406) that if you bind to the source attribute then it bails out of the recursive portion of kendo.bind. See here:
So all I had to do was bind to the source of the container to null:

Inherited control not rendered

I have a question about the Nevron Chart Control. I created a new and "empty" class myNevronChart that inherits from the NThinChartControl class. Then in the init event I created an instance of this class and added it to the Page controls collection but the form opens empty and the chart is not rendered. If I use NThinChartControl class instead of myNevronChart everything works fine and the chart renders.
You need to wait for a SP - the problem is that the control searches for some resources based on the assembly defining the chart control. When you override the control in your code you effectively change the assembly where the control looks for resources.

How to Dynamically load EXTERNAL MVVM and NON MVVM controls using Caliburn Micro

I am loading controls dynamically from the web server from separate XAP files. After creating an instance I want to show them in tab Pages. The controls can be MMVM controls using CM but also non MVVM standard controls.
Before trying the tab I tested to simply show a control dynamically on the page by using:
<ContentControl Name="TestControl" />
Test control is a property of Type UserControl which is set via creating a new Instance of a dynamically loaded control. Now this gives me an error that it can't find the view. In case of non MVVM controls there is of course no view, so how do I load a non MVVM control?
I tried to make the test control a MVVM control, but still get the cannot load view error. Makes sense as such instance is not created. If I create an instance of the dynamically loaded view besides the view model, how do I "Add" this so that CM finds it?
Last but not least, how do I bind this to a tab control in Silverlight? The idea is to have a collection of user controls (plugins) which each is rendered in its separate tab page.
Thanks for any help.
(I got this done in no time NOT using MVVM, still not sure if MVVM is worth all the complexity)
There's no such thing as "mvvm control". MVVM is just a pattern not a control type. Basically, in Caliburn you don't need to work vith UserControls or Views directly, but if you pick the ViewModel first approach, Caliburn framework should be able to find the matching view for you. In your case since you're loading XAP files dynamically, you need to add them to the list of assemblies Caliburn looks to find a View/ViewModel (and bind them together) and this is done through IAssemblySource interface. According to the documentation here:
So, what is AssemblySoure.Instance? This is the place that
Caliburn.Micro looks for Views. You can add assemblies to this at any
time during your application to make them available to the framework,
but there is also a special place to do it in the Bootstrapper.

How do i notify eclipse that an element was created

what is the standard way in eclipse to notify a view that an elment was added. In my cases i have one view in which items are created (tree viewer). Once that is done all other interrested parties shall be informed.
In another case all interrested views shall be informed if the data in an editor was changed. Should this be the save of an completly new object than this new item shall be added to a view.
What is the best way to do this without implmenting my own listener mechanism?
In your viewer's content provider there is a method:
public void inputChanged(Viewer viewer, Object oldInput, Object newInput);
According to the documentation:
Notifies this content provider that the given viewer's input has been
switched to a different element.
A typical use for this method is registering the content provider as a
listener to changes on the new input (using model-specific means), and
deregistering the viewer from the old input. In response to these
change notifications, the content provider should update the viewer
(see the add, remove, update and refresh methods on the viewers).
You can use this method to notify other classes that your input has changed. (i.e. - an element was added .. )

Eclipse Plug-in / View Question

I have a plugin which contains class A that brings up a view defined in class B via the following line of code:
(VideoLogView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("Videolog.VideoLogView");
What I need to do in the createPartControl() method of the view (class B object) is access a method in the class A object.
How can this be done?
Thanks.
Look like you are facing the classic issue of "how do I pass arguments to my view" ?
This thread illustrates it best:
I was facing the same problem at the beggining of my RCP project. I was getting weird about the fact that there was no way to pass an argument to a view as the viewed model.
Why? Because (emphasis mine):
You are on an opened, pluggable platform.
You contribute to existing developments, others should be able to contribute to yours.
Therefore you will not "pass" arguments to a view, this would lock the whole thing into a non-opened design.
Instead, your view will ask the platform (or will listen to the platform) to determine which information to manage.
Other views (from other plugins that don't yet exist) might also want to manage the same information on the same event.
What you should do then is to ask the workbench for the current selection. I guess your view is opening on a double click action or simple selection so the object you want to manage in your view will be currently selected.
This is how you could retrieve the workbench selection from your view :
ISelection s = this.getSite().getWorkbenchWindow().getSelectionService().getSelection();
where "this" is a ViewPart.
Then you have to make your initial view (the one initiating the view creation from a given event like DoubleClick) a selection provider. A JFace viewer is a selection provider, so you can use it if you're using jface, or you can implement the ISelectionProvider interface when you're using custom SWT controls (that was my case).
The article "Eclipse Workbench: Using the Selection Service" can also give you some pointers.