开发者

WPF Menu on Winforms

Is it p开发者_开发问答ossible to show WPF Context menu on WinForms?

If yes, how could we do that?


OK, so I've found the answer myself... (I tried to give a 50 point bounty, but I don't think I can award myself :P)

We have a lot of legacy WinForms... forms... still in our project at work. And here's the secret code that is needed to display a WPF Context Menu in a WinForms project!

var myMenu = new System.Windows.Controls.ContextMenu();
myMenu.Items.Add("One");
myMenu.Items.Add("Two");
myMenu.Items.Add("Three");
myMenu.IsOpen = true;

Tada!!! - There is no secret code needed... you can write this code in a WPF App or a WinForms app and it works the same.

And there's your answer :)


You can mix the 2 technologies using WindowsFormsHost (WinForm inside WPF window) and ElementHost (WPF inside WinForm window).

You will not encounter the Airspace issue as you are adding a WPF menu into a Winform application. But you will if you create WPF windows with Winform UserControls. This Blog post has some ideas about solving it, but it is not pretty.


I don't know if it can be done, but this article might help point you in the right direction. As a WPF developer, it seems strange to me to want to mix winforms and wpf, but i can see the case for re-use.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜