标签: c# .net wpf
我在WPF窗口的User Control下有一些通用Canvas。
User Control
Canvas
我如何才能获得该窗口?
我使用了这种方法
void UserControlMethod() { WindowInteropHelper WindowInteropHelper = new WindowInteropHelper((Window)((Grid)(((Canvas)this.Parent).Parent)).Parent); }
这是对的吗?
谢谢!
答案 0 :(得分:3)
您应该使用:Window.GetWindow()。
Window.GetWindow()
WindowInteropHelper用于与本机Windows代码或API交互,因此绝对不是您想要的。
WindowInteropHelper