Hooking Caliburn.Micro WindowManager up within Excel - c#

I have a problem that is similar to that posted here. I have posted before about using Caliburn.Micro in an Excel Document customization where the WPF controls are on an ActionsPane without receiving much help.
I currently have this working by placing the ShellView user control onto the design surface of the ActionsPane inside the ElementHost. Most things work as normal with Caliburn.Micro, however I do not get any Activate or Deactivate events because I haven't got a reference to a Caliburn.Micro WindowManager.
If I create a new window manager and use it to show a window using ShowWindow, then the window appears as a completely separate window (not in the ActionPane) however I do get Activate/Deactivate events.
Is there some way to attach Caliburn.Micro's Window manager to the ActionPane within Excel. I already have a MEF Bootstrapper passing false to BootstrapperBase.
Regards
Alan

Related

Handling a framework-specific event and MVVM?

In a WPF application that uses Prism, I have a shell in which there is a docking manager control.
Now I have to listen to an event coming from that docking manager, specifically, when one of its children docking state has changed.
To me, this event should be handled in code-behind as letting the view model do some work against that framework-specific visual control is worse than doing it code-behind.
Question:
Is this the right approach or am I missing something?
As long as the code is only related for the presentation then it is no problem to have it in "code-behind".
The main problem with "code-behind" is having the presentation logic split in two different locations XAML and "code-behind". There are several ways to avoid that using MarkupExtension, DependencyProperty, ValueConverter or custom (derived) controls.

WPF UserControl that is a tab in a tabcontrol - how to detect if it is closing

I have a class that is inheriting from a UserControl. I am showing this class in a WPF TabControl as a tab. The tab has a small x and can be closed by clicking on it. I need a way to do some cleanup code before the tab is destroyed.
I don't believe I can use the Unloaded event to do this because the Unloaded event is called when the UserControl is being destroyed and it is also being called when you click on another tab.
Any ideas on how to deal with this situation?
EDIT:
Here is more info.
In my UserControl class I have a 3rd part control that I am using. Basically a graphing control. There are a couple lines of code I would like to run to ensure that there are no memory leaks. If you want to read more about it then this would be the web address that talks more about it:
http://support.scichart.com/index.php?/News/NewsItem/View/21/wpf-xname-memory-leak--how-to-clear-memory-in-scichart
You can have a look at the way I have done this in the dragablz TabControl on GitHub.
Essentially the TabControl listens to a RoutedCommend raised from the close button, then calls an optional callback which enables a MVVM view model (or old-style control type code) to dispose an associated view model, or perform any other tidy up code you want to do (or indeed cancel the close operation).
In the example project file on GitHub, look for ClosingItemHandlerImpl and work back from there.
http://github.com/ButchersBoy/Dragablz/blob/master/DragablzDemo/BoundExampleModel.cs
ClosingItemHandlerImpl is bound in from the XAML, and the tab control will call it prior to removing a tab.

Windows 8 styled popup window using Prism c# WPF

I'm trying to create a modal popup window using the windows 8 style popup.
If I use the standard prism popup methods as described here :
http://msdn.microsoft.com/en-us/library/ff921081%28v=pandp.40%29.aspx
I only end up getting new windows. What I want is to have a popup that stays in the context of my window. I just can't find anyway of accomplishing this with a modal popup. Has anyone attempted this or knows of a way this can be accomplished?
Although nice, you won't be able to use the PopupWindowAction since inherently it uses a new window. You can, however, manually add an event handler to the event in your ViewModel from the code behind and do your interactivity there.

How do I Bind to a Collection and Display Information Based on Selection through a Dialog Box in WPF?

I am fairly new to WPF, and I'm currently creating a desktop application for work. I have been doing a bit of research on databinding and came across this How-to article in the MSDN Library:
http://msdn.microsoft.com/en-us/library/aa970558.aspx
Right now the problem I'm faced with is implementing this to my application. I want to modify this by having the information displayed in a dialog box instead of the same window the collection is in. How can I implement this in C#/xaml?
you have to add another window to the project. Then you need to instantiate that window from your mainwindow trough a button click for instance. Then you have to set that new window datacontext.
See this link, it shows how to create another window and pass the datacontext.
Hope it helps.

Issues refreshing winforms controls in WPF Host?

I have been looking at Prism to host an old Winforms application. This is being used in our migration from Winforms -> WPF in our company. However, I have come across some issues.
In short I have a project outlined like so:
Project Outline
DataManager WPF Project
MEF Module that on Initialize registers a view with the region manager and references the old winforms project
- View -- which contains a WPF UserControl and has a WindowsFormsHost which points to the main view of the old winforms project.
DataManager Winforms project
Contains an old Module that needs to be intialized with views
Host
Contains the shell and bootstrapper
- Shell has the main region in which the WPF DataManager View gets injected into.
So the problem I am having is as follows. The old Winforms view loads correctly in the WPF shell via the new WPF view. However, any content added to the view after this does not get updated. I tried adding some buttons to the screen. I also tried clearing all the controls.
Looking around here, I went with the suggestion of listening to the Size Changed event and calling Child.Refresh on the WPFHost, but still this did not work.
Is this a WPF specific issue like discussed here : Does WPF refresh drawing similar to Windows Forms?
Or is it an issue with not refreshing the view in the region manager correctly? WPF, Prism v2, Region in a modal dialog, add region in code behind
Neither of which seem to work!
Perhaps I need to fire a redraw or similar in the winforms control itself?
Edit: Calling a Refresh() after updating the UI did not resolve the issue.
Edit 2: Also tried this in the old Winforms (.net 2.0) application and it displayed correctly!
Ok, I added a standard winforms project with some controls instead of the legacy project I am using and it worked. It is possibly missing some steps in the initialization of the legacy winforms project.

Categories

Resources