WPF : Getting the sender of UserControl - wpf

I am having WPF MVVM application. I am having UserControl.
From few places in application I am calling this UserControl. User Control contains Image which show camera stream and back button.
The problem is when I click "Back" in UserControl I would like to know who called it.
Does anyone know how I can get sender?

Related

WPF Notification Balloon using a User Control

I am working in a WPF app in C# and it is really very very sad that WPF doesn't have a NotifyIcon like in the Win forms has. I have seen a lot of articles in the net for a wpf notifyicon balloon notification project. But none satisfied me. See, I have an idea but i don't know how to execute it.
Create a wpf user control with height and width same like the notifyicon.
Put a border control in it with corner radius 5. Put a grid inside that border control to place the textblocks and images.
Then position that user control to the system tray area. When we click a button from a window, this user control shows up just above the system tray and it hides when we click on outside area.
Is this possible to place the user control [this new "notifyicon" ] just above the system tray area ???
You can do this using an AdornerDecorater in you XAML.
Check this project out GitHub. It has a configurable notification toast popup control for WPF with a demo app.

Popup topmost only outlook window

I have created a Outlook Addin Project and I used WPF user control as element host in UserControl(WinForm) which is loaded using Custom Task Pane.
I have some dragoperation in wpf usercontrol which will open Popup.
The problem is the popup is showing topmost window for all the windows.
I need to show/visible only when outlook window activated. Appreciate your help
You need to make sure your popup is a child of the appropriate Outlook window. You cast Outlook Inspector or Explorer object to IOleWindow interface and call IOleWindow.GetWindow to retrieve HWND. You can then use WindowInteropHelper class along with the retrieved HWND to display your window.

WPF Displaying Windows

I have been looking for a good tutorial on WPF, MVVM and windows navigation. I am trying to display a new window once a user clicks an "ok" button. Does anyone know how to go about doing this?
To display a new window using an OK button, you need to create a new instance of the window and call it's Show() method. You can either do this in the button click event (code behind) or bind it to a custom Command object (MVVM). Here's the code to open a window.
var window = new MainWindow();
window.Show();
In MVVM, some developers choose to just have 1 Window, usually MainWindow, and separate parts of their UI into UserControls. They use DataTemplates to define which UserControl appears in the MainWindow.
There are a lot of tutorials on MVVM if you just take time to Google this topic. Here's a few links that have helped me a lot.
http://rachel53461.wordpress.com/2011/12/18/navigation-with-mvvm-2/
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

ActiveX control doesn't get focus when right-clicked

I'm working on an ActiveX control which is hosted in MFC and VB6 applications.
This ActiveX contains a WPF control, itself hosted by a WinForms ElementHost, i.e.:
MFC > .NET ActiveX > WinForms ElementHost > WPF UserControl
When an user right-clicks on the control, he must be able to navigate in the contextual menu using the keyboard arrow keys.
If my control has the focus when the right-click occurs, everything works fine.
But if the focus is in the host application when the user right-clicks, keyboard events continue to be sent to the host MFC application.
I tried to call the Focus() method on my WPF control when I detect the right click, but it doesn't work.
Does anybody have an idea ?
Thanks.
I have found a workaround.
When the PreviewMouseRightButtonDown event occurs on the WPF form, I call the Focus method on the WinForm host control.
I don't really understand why, but this lets users use their keyboards to navigate in the contextual menu.

How to prevent WebBrowser control from stealing focus from other text box in my WPF form

My WPF app has a window with various text boxes and a WebBrowser control.
The WebBrower control is used to show a web site (I doesn't own) and then a Login button in the WPF window fills the fields in the site from the text boxes.
The problem is that the web site calls focus() method on one of its input fields on load, and that still the focus from the text box in my WPF window. I want the focus to be on the WPF window field and not in the web page within the WebBrowser control.
I tryed calling MyTextBox.Focus() in the WebBrowser's LoadCompleted event, but to no avail. Setting the WebBrowser's IsEnabled or even Visibility properties didn't help either.
Does anyone have an idea how I can overcome this and move the focus to the WPF control instead of the web page input field?
Don't think you can extend the control site to add IProtectFocus to the site. Try interop the Windows Forms version of the webbrowser control and override the CreateWebBrowserSiteBase method to provide your own control site.

Resources