C# WPF AutomationElement NativeWindowHandle

C# WPF AutomationElement NativeWindowHandle,c#,wpf,C#,Wpf,我有这个: this.DialogCDKey = this.ApplicationElement.FindFirst(TreeScope.Children, this.ConditionDialogTitleCDKey); 当我在这行之后运行并中断时,我会看到对话框cdkeyInfo,它是一个自动元素。 滚动信息时,我会看到NativeWindowHandle。 我想将其分配给IntPtr,如下所示: IntPtr WindowHandle = this.DialogCDKey.Current

我有这个:

this.DialogCDKey = this.ApplicationElement.FindFirst(TreeScope.Children, this.ConditionDialogTitleCDKey);
当我在这行之后运行并中断时,我会看到
对话框cdkey
Info,它是一个
自动元素
。 滚动信息时,我会看到
NativeWindowHandle
。 我想将其分配给
IntPtr
,如下所示:

IntPtr WindowHandle = this.DialogCDKey.Current.NativeWindowHandle();

但是MSV不买这个,我哪里出错了?

这个应该可以用,你试过了吗

IntPtr WindowHandle = new IntPtr(this.DialogCDKey.Current.NativeWindowHandle);

这应该行得通,你试过吗

IntPtr WindowHandle = new IntPtr(this.DialogCDKey.Current.NativeWindowHandle);
属性的类型为
int
。整数可以显式地为:

var WindowHandle = (IntPtr) (this.DialogCDKey.Current.NativeWindowHandle);
在内部,将
int
强制转换为
IntPtr
与创建一个新的
IntPtr
实例相同,因此您可以执行自己喜欢的操作。这是上述cast在中的实现:

属性的类型为
int
。整数可以显式地为:

var WindowHandle = (IntPtr) (this.DialogCDKey.Current.NativeWindowHandle);
在内部,将
int
强制转换为
IntPtr
与创建一个新的
IntPtr
实例相同,因此您可以执行自己喜欢的操作。这是上述cast在中的实现:


@TBBW更新为转换与创建
IntPtr
的新实例之间的差异@TBBW更新为转换与创建
IntPtr
的新实例之间的差异。