WPF 窗口托管用户控件 [英] WPF window hosting usercontrol
本文介绍了WPF 窗口托管用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用户控件,用于编辑应用程序中的某些对象.
I have a usercontrol that I use to edit some objects in my application.
我最近遇到了一个实例,我想弹出一个新的对话框(窗口)来承载这个用户控件.
I have recently come to an instance where I want to pop up a new dialog (window) which will host this usercontrol.
如何实例化新窗口并将需要从窗口设置的任何属性传递给用户控件?
How do I instantiate the new window and pass any properties that need to be set from the window to the usercontrol?
感谢您的时间.
推荐答案
您可以简单地将新窗口的内容设置为您的用户控件.在代码中,这将是这样的:
You can simply set the content of your new window to your user control. In code, this would be something like this:
...
MyUserControl userControl = new MyUserControl();
//... set up bindings, etc (probably set up in user control xaml) ...
Window newWindow = new Window();
newWindow.Content = userControl;
newWindow.Show();
...
这篇关于WPF 窗口托管用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文