OnHandleCreated的WPF等价物(来自C#) [英] WPF equivalent for OnHandleCreated (from C#)

查看:197
本文介绍了OnHandleCreated的WPF等价物(来自C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于WPF中的窗口,OnHandleCreated是否有任何等效的表格,就像C#中的表格一样?



我的意图是得到窗口的句柄和不是它的儿童控制。我想在创建后访问此句柄。在winforms中,我们可以使用OnHandleCreated在创建时立即获取句柄。在WPF窗口中是否可以替代它?



任何帮助都将不胜感激。在此先感谢。

Is there any equivalent for OnHandleCreated for a window in WPF as is there in C# for a form?

My intention is to get the handle for the window and not for it's child controls. I want to access this handle after it is created. In winforms we could use OnHandleCreated to get the handle as soon as it is created. Is it any alternative for this in WPF window?

Any help would be appreciated. Thanks in advance.

推荐答案

您好,



您可以尝试:



Hi,

You can try:

class MyWindow : Window
{
    protected override void OnSourceInitialized(EventArgs e)
    {
         base.OnSourceInitialized(e);
         var handle = new WindowInteropHelper(this).Handle;
         // -- or --
         var hwndSource = (HwndSource)PresentationSource.FromVisual(this);
         var handle = hwndSource.Handle;
    }
}


这篇关于OnHandleCreated的WPF等价物(来自C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆