我有一个UserControl
在任务栏中显示一个没有图标的窗口,问题是当主窗口失去焦点并再次获取它时,没有任务栏图标的窗口位于主窗口后面,很难显示它在前面,当类是一个窗口时,使用window.Owner = this;
来解决此问题,但是当UserControl
或其他类型(例如ListBoxItem
,Viewbox
)我可以'这样做。我尝试执行此操作control.Owner = (Window)this;
,但结果会引发一个异常,即Grid
无法转换为Window
答案 0 :(得分:7)
使用
window.Owner = Window.GetWindow(this);
答案 1 :(得分:1)
for (int index=0;index< App.Current.Windows.Count;index++ )
{
if (App.Current.Windows[index].Title == "MyWindow")
control.Owner = App.Current.Windows[index];
}
此处标题是您要设置为所有者的窗口标题。