0

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>

EitanG
  • 221
  • 4
  • 19
  • This code is showing a Windows Form inside a WPF control which doesn't match your question. Where's the parent Windows Form? – ChrisF Mar 06 '12 at 13:00
  • @ChrisF my guess is, he wants the WPF button on top of the TextBox. So either he has a problem with wpf working with winforms or its a simple layouting issue. – dowhilefor Mar 06 '12 at 13:05
  • Hi ChrisF, I will sharp my question, I want that the WPF Button will be shown on top of the Winform TextBox. – EitanG Mar 06 '12 at 13:11
  • Similar problem as here http://stackoverflow.com/questions/5978917/render-wpf-control-on-top-of-windowsformshost – Klaus78 Mar 06 '12 at 14:13

3 Answers3

3

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.

dowhilefor
  • 10,971
  • 3
  • 28
  • 45
  • .NET 4.5 addresses the airspace issue: http://msdn.microsoft.com/en-us/library/bb613588(v=VS.110).aspx#airspace – myermian Mar 06 '12 at 13:09
  • The Layout that I want is the WPF Button on top of the winform TextBox . – EitanG Mar 06 '12 at 13:13
  • @m-y Yes its valuable to add this information, unfortunately the question is missing the used WPF version. – dowhilefor Mar 06 '12 at 13:14
  • @EitanG Yes but it seems, like i already wrote, you are suffering from the airspace problem. Please read the link to understand that this has nothing to do with layouting, which is fine by itself, but with rendering between winforms and wpf. – dowhilefor Mar 06 '12 at 13:15
  • @dowhilefor I've read the link to the airspace problem. do you know of any known solution for that ? – EitanG Mar 06 '12 at 13:17
  • Well first of all, like m-y suggested: Using WPF 4.5 should remove this problem all together. We had a similar problem with direct3d and wpf, and we rendered the whole content into a WPF Surface and displayed that, but of course we had to rewrite all user interaction code, which was for our case not a big deal. But this would be a huge task for winforms. So my advice is, why not use a WPF Textbox? – dowhilefor Mar 06 '12 at 13:52
0

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.

Viktar
  • 129
  • 6
0

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."

teushine
  • 1
  • 1