【VS Shell Integrated】在VS.Net 2008 IDE中如何设置直接弹出的WPF窗体的Owner(对<在VS.Net 2008 IDE中直接使用WPF窗体作为弹出窗体>的补充
2010-03-18 10:24
661 查看
理虽是这个理但是怎么设呢,层层包裹,皮厚的很啊,如下图.
怎么办,烧香,请GOOGLE大兄,结果找到下面这文章:
查看下文时,先看上面引用的文章
但是关键的代码没写,真是杯具啊
//Getthehandletothenon-WPFownerwindow IntPtrownerWindowHandle=...;//GethWndfornon-WPFwindow
没法子,发信给作者,问他怎么能直接得到ToolWindow或IDE的handle.
结果是微软DeveloperDivisionUserEducation的一个姐姐(不知年龄)给了回复.不过,来来回回,好像她还是没完全搞明白程序结构.
只给了一些基本的提示,有些用处,但是没解决根本性问题,不过还是非常感谢这位姐姐.
我这一看,看来玩直接的是不行啦,咱变通一下吧,用点间接方法吧,很简单,就是通过实例成员,传!
1)在WPF用户控件定义一个成员变量ParentHandle
publicpartialclassExplorerControlWPF:System.Windows.Controls.UserControl
{
publicExplorerControlWPF()
{
InitializeComponent();
}
publicIntPtrParentHandle;
2)在Winform用户控件中传递Handle
publicpartialclassExplorerControl:System.Windows.Forms.UserControl
{
publicExplorerControl()
{
InitializeComponent();
//
//传ElementHost的Handle
//
//或者传ExplorerControl.Handle
//(this.elementHost1.ChildasExplorerControlWPF).ParentHandle=this.elementHost1.Parent.Handl
//
(this.elementHost1.ChildasExplorerControlWPF).ParentHandle=this.elementHost1.Handle;
}
3)经过上述步骤,就可以在WPF用户控件ExplorerControlWPF中使用Handle了
privatevoidMuNewProject_Click(objectsender,RoutedEventArgse)
{
RegProjectFormRegWin=newRegProjectForm();
WindowInteropHelperhelper=newWindowInteropHelper(RegWin);
helper.Owner=this.ParentHandle;
try
{
if(RegWin.ShowDialog()==true)
{
运行,大功告成!
通过类似的方法,也可以把ToolWindow的Handle传给ExplorerControlWPF
1)在ExplorerControl,声明一个成员变量ParentWindow
publicpartialclassExplorerControl:System.Windows.Forms.UserControl
{
publicToolWindowPaneParentWindow;
publicExplorerControl()
{
InitializeComponent();
//
//传ElementHost的Handle
//
//或者传ExplorerControl.Handle
//(this.elementHost1.ChildasExplorerControlWPF).ParentHandle=this.elementHost1.Parent.Handl
//
//(this.elementHost1.ChildasExplorerControlWPF).ParentHandle=this.elementHost1.Handle;
}
2)在ToolWindow里,把自身传给ExplorerControl的实例
[Guid("e6a26ad4-7f6d-48e1-b1b4-dfb65654800f")]
publicclassExplorerForm:ToolWindowPane
{
privateExplorerControlContentControl;
publicExplorerForm():
base(null)
{
this.Caption=UiResources.ExplorerWindowTitle;
this.BitmapResourceID=301;
this.BitmapIndex=1;
this.ContentControl=newExplorerControl();
//传递自身
this.ContentControl.ParentWindow=this;
}
3)在ExplorerControl的OnLoad事件中传递ToolWindow的handle给ExplorerControlWPF.
注意:不是在构造函数里,因为这时ParentWindow还没被赋上引用.
publicpartialclassExplorerControl:System.Windows.Forms.UserControl
{
publicToolWindowPaneParentWindow;
publicExplorerControl()
{
InitializeComponent();
//
//传ElementHost的Handle
//
//或者传ExplorerControl.Handle
//(this.elementHost1.ChildasExplorerControlWPF).ParentHandle=this.elementHost1.Parent.Handle
//
//(this.elementHost1.ChildasExplorerControlWPF).ParentHandle=this.elementHost1.Handle;
}
protectedoverridevoidOnLoad(EventArgse)
{
(this.elementHost1.ChildasExplorerControlWPF).ParentHandle=this.ParentWindow.Window.Handle;
base.OnLoad(e);
}
4)经过上述步骤,就可以在WPF用户控件ExplorerControlWPF中使用Handle了
privatevoidMuNewProject_Click(objectsender,RoutedEventArgse)
{
RegProjectFormRegWin=newRegProjectForm();
WindowInteropHelperhelper=newWindowInteropHelper(RegWin);
helper.Owner=this.ParentHandle;
try
{
if(RegWin.ShowDialog()==true)
{
运行,大功告成!
这三个Handle,传哪一个都可以,效果完全一致.
相关文章推荐
- [WPF]如何实现设置UserControl 弹出窗口的Owner属性功能
- [WPF]如何实现设置弹出窗口的Owner属性功能?
- 【WPF】设置UserControl弹出窗体时的Owner
- VS.NET IDE <Table>使用小技巧
- vs 2008 win32程序使用大内存 (>2GB)设置
- vs 2008 win32程序使用大内存 (>2GB)设置
- 技巧百问(2):在asp.net网页中如何使用弹出窗体?
- [WPF]如何实现设置UserControl 弹出窗口的Owner属性功能
- vs 2008 win32程序使用大内存 (>2GB)设置
- 使用VS.NET生成word文档并直接下载
- 在WPF程序中使用摄像头兼谈如何使用AForge.NET控件
- 使用VS.NET生成word文档并直接下载
- Struts标签-如何使用<s:select>标签
- vs 2008中使用Asp.net Ajax智能感知Intellisense
- 如何使用VS.NET调试数据库存储过程 (转)
- 如何使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- 如何将PHP作为Shell脚本语言使用
- 在dll工程中使用mfc资源,窗体无法弹出如何解决?(文章内容均系转载,读者尚未理解)
- VS.Net 2005中如何:使用“编辑并继续”
- 使用VS.Net IDE调试JavaScript