开发者

WPF App - How to obtain a reference to the corresponding System.Windows.Forms.Form?

开发者 https://www.devze.com 2022-12-09 00:44 出处:网络
In my WPF Project I have a WPF Window. I want to use Sticky Windows Solution i开发者_StackOverflow中文版n my WPF Project. The library wants only one parameter: the System.Windows.Forms.Form object.

In my WPF Project I have a WPF Window. I want to use Sticky Windows Solution i开发者_StackOverflow中文版n my WPF Project. The library wants only one parameter: the System.Windows.Forms.Form object.

Does it exist any way to obtain a Form object starting from a WPF Window object?


No, it's not possible. A WPF Window has no inheritance relation with a Windows Forms Form. However it would probably be possible to adapt the code from the library to mentioned so that it works with WPF...


The approach others have mentioned of refactoring Sticky Windows Solution to support WPF forms sounds like your best option. If you really want to treat a WPF form as a Windows Form, maybe the below will help:

Would this work?

  • Host your WPF form in an ElementHost control. (ElementHost enables a WPF element to be treated as a Windows Form control.)
  • Create a simple Windows Form containing only this ElementHost control.
  • Use a reference to this Windows Form in your Sticky Windows Solution.


While it's not possible, the article and code does present enough information for you to create a WPF version.

0

精彩评论

暂无评论...
验证码 换一张
取 消