WPF elements are resolved by WinForm control masking issues after using WinForm controls

Source: Internet
Author: User

Some would say that it is not recommended to use the WinForm control in WPF, and some would say that it is recommended to use an alternative to WinForm control under WPF, but in practice, due to the special needs of the project, time, cost and other factors are often encountered in the use of Winfrom control in WPF. We know that WPF can invoke the WinForm control by using the WindowsFormsHost container, but there are occasions when WPF elements need to be displayed on top of the WinForm control, where WPF elements are obscured by WinForm controls.

First, scene reproduction

Received the company orders, in the case of tight time, the original WinForm program (others wrote, they did not participate in anything) to replace the implementation of WPF, the interface to do a beauty. First look at the source code, understand the knowledge inside the blind spot, the main one is for the map display of the Gmap.net component (an open source GIS two development components), then to Gmap.net to understand: Gmap.net is divided into for WinForm and form WPF, And there is no layer under the concept of WPF, some class structure of the design of the month GMap.net.winform change, in order to secure, no unnecessary trouble, rapid revision response to project requirements, consider still using the GMap.net.winform, only the display layer to make changes.

1. Add the two DLL references required by WPF to invoke the WinForm control:WindowsFormsIntegration.dll, Two DLL references for System.Windows.Forms.dll and GMap.Net.WindowsFroms: GMap.Net.Core.dll and GMap.Net.WindowsForms.dll.

2. When the program runs, the Mapcontrol control is loaded into the WindowsFormsHost container after processing.

Front desk Key code:

+ View Code

Background key Code

+ View Code

The legend area at the lower right corner of the design state is set to the topmost level, as shown in no problem

When the program runs, the Gmapcontrol control of the WinForm type is rendered at the topmost level, overwriting the WPF element that displays the lower-right corner of the map legend area.

Second, Seek solutions

I first tried a variety of WPF interface layout, Canvas, various panel and so on have tried again, the result is still WPF elements are obscured by the WinForm control, so to seek network help, the answer is basically as follows:

Third, the Final Solution

Consider if the WinForm control is always rendered at the top level because of a rendering mechanism, can the WPF element also use the WindowsFormsHost container for a layer of wrapping? Theoretically it should be possible, so try, outermost use windosformshost, then the WPF element container ElementHost, and finally the WPF interface element we need:

+ View Code

To run a program problem resolution:

WPF elements are resolved by WinForm control masking issues after using WinForm controls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.