EitanG
EitanG

Reputation: 221

Can't see WPF control on top Winform Control

I want to show WPF control on top Winform Control. I want that the WPF Button will appear on top on the Winform TextBox.

The result is that the WPF control is hidden in the back of the winform TextBox and I can't see it. Why is that?

This is my code:

<UserControl x:Class="Philips.PmsCT.Host.Applications.ExamApplication.ScanRulerComponent.WPFHostWF"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Width="800" Height="120">
<Grid>
    <WindowsFormsHost >
        <wf:TextBox  BackColor="LightBlue" />
    </WindowsFormsHost>
    <Button Width="100" Height="25" Background="Red"/>
</Grid>

Upvotes: 0

Views: 2657

Answers (3)

teushine
teushine

Reputation: 1

In according to the Microsoft docs: "Visible WindowsFormsHost elements are always drawn on top of other WPF elements, and they are unaffected by z-order."

Upvotes: 0

Viktar
Viktar

Reputation: 129

All WPF controls render in one native window. You can check it via SPY++ for example. Almost each WindowsForm Control renders in it own window. Again, you can check it via SPY++. You want to produce behavior when one window A(WPF) is covered by another window B(Winform control). At the same time you want window B is covered by A(wpf button). I don't know if it can be possible without any hook. Possible solutions is: 1. Host WPF inside WinForm Panel, where TextBox is. 2. Create WPF form with only required button and show it over first form.

Upvotes: 0

dowhilefor
dowhilefor

Reputation: 11051

You seem to have the Airspace problem. So you can rearrange the two controls, that they are layouted next to each other, not on top of each other or use the Wpf TextBox or you have to really bend over backwards to mitigate the airspace problem all together.

Upvotes: 3

Related Questions