回答
你的控制必须位于一个窗口
Window Window = new Window();
// window has a single content
// here it is usercontrol1
// to have many controls, use an intermediary like Grid or Canvas or any Panel derived class
window.Content = usercontrol1;
在窗口被打开。
// modeless (non blocking) opening
window.Show();
或
// modal (blocking) opening
window.Showdialog();
问候
可能更容易将UserControl更改为一个窗口(请参阅我的答案)比深层包装UserControl两层(WinForm> ElementHost> UserControl)更容易。更好地接触孩子。 –
不能显示UserControl
。将UserControl
更改为Window
。
XAML:
<Window x:Class="WindowsFormsApplication1.MyWindow"
,而不是
<UserControl x:Class="WindowsFormsApplication1.UserControl1"
,并在您的代码隐藏,更改
public partial class UserControl1 : UserControl
到
public partial class MyWindow: Window
现在您可以致电new MyWindow().Show();
。主要好处是您不会通过在其中添加Windows窗体对话框和ElementHost以及UserControl来使应用程序负担过重。
这样,您还可以从调用Windows窗体类访问UserControl/Window的子项。
但UserControl不是一个窗口。不要用狗的名字命名猫!我同意,你可以忘记Usercontrol并直接创建一个窗口 –
@EmmanuelDURIN同意 - 以后可能会导致麻烦。懒惰的命名约定。更新了答案。 –
- 1. opeing形式,C#windows窗体
- 2. Windows窗体形式不看本地
- 3. 适用于WPF和Windows窗体的图像表示形式
- 4. 在WPF窗体C中查看二维数组#
- 5. WPF或Windows窗体
- 6. 在Windows窗体或WPF
- 7. 显示在WPF Windows窗体
- 8. 使用C#在Windows窗体中查看PDF
- 9. Windows窗体中BackgroundImage的位置形式
- 10. Windows窗体中的“iframes”形式
- 11. C#添加WPF按钮到Windows窗体
- 12. 使用Windows窗体的WPF
- 13. 在Windows窗体中查找所有ContextMenuStrips形式
- 14. 窗体查看如何检查模式
- 15. c#windows窗体
- 16. Windows窗体C#
- 17. Windows窗体中的图形
- 18. 从Windows窗体到WPF
- 19. WPF与Windows窗体 - STAThread
- 20. WPF DataGrid与Windows窗体DataGridView
- 21. 集成WPF和Windows窗体
- 22. 共存Windows窗体和WPF
- 23. C#Windows窗体列表查看选定项目
- 24. C#窗体中的一种新形式
- 25. C#Windows窗体的设计模式
- 26. 如何使不具有标准的Windows窗体看看C#
- 27. Windows窗体按钮在C#
- 28. Windows窗体图形闪烁
- 29. Windows窗体combobox.SelectedItem,C#
- 30. 转换Windows窗体的OnPaint等效WPF形状
我只是再读一遍这个问题的标题:你想混合使用WPF和Windows窗体技术吗?如果是的话,UserControl是Windows窗体技术,Windows是Windows窗体,还是相反?如果不是,则标题应该更改 –
请您回答一下WPF/Windows窗体,以便可以根据需要更新帖子的标题。问候 –