I have an UserControl
that shows a window without an icon in the Taskbar, the problem is when the main window lost the focus and get it again the window without taskbar icon is behind the main window and is difficult show it in front again, this issue is solved using window.Owner = this;
when the class is a window, but when is UserControl
or other type (e.g. ListBoxItem
, Viewbox
) I can't do this. I tried to do this control.Owner = (Window)this;
but the result throws an exception that a Grid
cannot be converted into a Window
Asked
Active
Viewed 6,694 times
2

FukYouAll
- 111
- 1
- 3
- 15
-
3maybe `control.Owner = Application.Current.MainWindow;` – sa_ddam213 Aug 19 '13 at 03:42
-
Or may be you can find the visual parent window via VisualTreeHelper. – D J Aug 19 '13 at 03:57
2 Answers
1
for (int index=0;index< App.Current.Windows.Count;index++ )
{
if (App.Current.Windows[index].Title == "MyWindow")
control.Owner = App.Current.Windows[index];
}
here Title is the Title of Window which you want to set as owner.

yo chauhan
- 12,079
- 4
- 39
- 58
-
Thanks for the answer, is not exactly I'm trying to solve, but I've found it useful in some parts of the application I'm creating, Thanks, I'll give +1. – FukYouAll Aug 20 '13 at 06:24