PreviewControl over all other controls?

swfaust
Advocate

PreviewControl over all other controls?

swfaust
Advocate
Advocate

I have a WPF window that I'm using a PreviewControl on.  This window also has a 'flyout' for help that is part of a template.  The flyout is on the template as the last listed item, so it's z index should be above anything inside the main frame which is where the preview control is placed.  I even set the Panel.ZIndex on the flyout to 5000, yet the preview control still renders over the top of it:

 

Preview Control Issue.png

 

Is this a known issue?  More important is there a way to get it to render in it's proper index so the flyout covers it like it should?  All other wpf controls render under the flyout  but PreviewControl does not.

 

Also the PreviewControl is constructed in the winow constructor and added dynamically as it can't be generated otherwise as far as I understand.  Here is the code:

 

var pc = new PreviewControl(doc, vw.Id) {IsManipulationEnabled = true};
pc.SetValue(Panel.ZIndexProperty, 20);

gd_PreviewControl.Children.Add(pc);

 

As you can see I also tried setting the z index of the preview control well below that of the flyout but still no luck.

0 Likes
Reply
2,541 Views
14 Replies
Replies (14)

JimJia
Alumni
Alumni

Dear swfaust,

 

Following is from API document:

"PreviewControl Class

The dialog or form or window host this preview control must be modal."
Because it is modal, it will allways show topmost.
 
If you want to let "flyout" show topmost, you may need to hide PreviewControl.
 

Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
0 Likes

swfaust
Advocate
Advocate

I understand that, but this isn't two separate windows, it's two controls on the same (modal) window.  It's like the preview control draws itself above everything else on the window...

0 Likes

JimJia
Alumni
Alumni

Hi,

Do you really want "flyout" on the top of PreviewControl?

You can use 'Grid' or 'StackPanel' to avoid that case. 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
0 Likes

swfaust
Advocate
Advocate

Yes I do...  Not permanently, but yes.  if the user presses the help button in the top right corner, the flyout rolls out and should be over everything else until the user dismisses it.  So it's not permanently over it, but when it is open and active it should be, similar to a dropdown menu...  Grid and StackPanel aren't what I'm looking for.

 

So is there something in the way PreviewControl is rendered that keeps it above other controls?

0 Likes

JimJia
Alumni
Alumni

Hi, 

Following is what I test.

It seems work well for PreviewControl.

 

previewcontrol.png

 

If you can provide a copy of your codes, maybe we can find out the solution.

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
0 Likes

swfaust
Advocate
Advocate

what you show there is a SEPARATE dialog window being shown on top of the one with the preview control.  I am talking about different CONTROLS on the SAME window...

0 Likes

JimJia
Alumni
Alumni

I'm afraid that, it seems PreviewControl can not set to back. It is always front.


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
0 Likes

swfaust
Advocate
Advocate

Ok well that stinks, would like to submit that as a feature request...

 

Also I tried to work around this by taking a screen shot of the preview control (using RenderTargetBitmap.Render() method and passing the preview control) and hiding the actual preview control and showing the image of it while the flyout is open.  However, apparently this doesn't work on preview control either.  I got exactly what I wanted when I tested it out using other WPF controls on the window, but preview control just ends up with a blank image, no go there too.  When I screen shot the entire window I get all controls except for the preview control, that area is just blank.

 

Can't find any way around this except to try and move preview control somewhere that is never under anything...  If anyone else has a better suggestion I would love to hear it :).

0 Likes

mastjaso
Advocate
Advocate

I don't think this is a "better" solution, but instead of screenshotting your preview control, you could export an image of the view that that preview control is displaying... It won't necessarily be zoomed/cropped correctly and I'm not sure if you can determine the zoom level and stuff to calculate it from the preview control, but it might still be good enough / better than nothing since you basically just want a temporary placeholder.

 

Again, not a real solution, just a crappy workaround, but might be better than nothing. More info:       http://forums.autodesk.com/t5/revit-api/how-to-export-an-image-from-a-specific-view-using-revit-api-...

0 Likes

swfaust
Advocate
Advocate

Yeah I tried that and didn't really get it.  Exporting the view like that would lose the view cube, etc. that's in the view.  I did look up and try some screen capture code to capture that part of the screen, but the ones I found either didn't work or were thrown off by screen magnification on high res displays.

 

Ultimately we ended up changing the UI around so that the preview control was never under the flyout portion.  Not great that we had to do that but we couldn't find any other way around.

0 Likes

RPTHOMAS108
Mentor
Mentor

Can't replicate the issue:

 

PreviewCtrlEx.png

 

Not sure how the Flyout acts differently to say a tooltip as the Flyout control isn't inherent to WPF, as far as I can tell. Perhaps however it is because I add preview control to a grid within it's own row rather than as a direct child to the grid or window? Or perhaps they fixed it in Revit version I was using. Thought previously that perhaps there is an event relating to the display of the Flyout that could temporarily collapse the PreviewControl.

 

<Window x:Class="PreviewControlWindow1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="PreviewControlWindow1" Height="300" Width="300">
    <Grid Name="MainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <ComboBox Grid.Row="0">
            <ComboBox.ToolTip>
                <ToolTip  Placement="Bottom" Width="70" Height="auto">
                    <TextBlock TextWrapping="Wrap">This is a tooltip with helpfull advice (sometimes).</TextBlock>
                </ToolTip>
            </ComboBox.ToolTip>
            <ComboBoxItem>Item1</ComboBoxItem>
            <ComboBoxItem>Item2</ComboBoxItem>
            <ComboBoxItem>Item3</ComboBoxItem>
            <ComboBoxItem>Item4</ComboBoxItem>
            <ComboBoxItem>Item5</ComboBoxItem>
            <ComboBoxItem>Item6</ComboBoxItem>
        </ComboBox>
       </Grid>
</Window>
 Private Function TObj23(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData, _
         ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) As Result

        If commandData.Application.ActiveUIDocument Is Nothing Then Return Result.Cancelled Else 

        Dim PCW As New PreviewControlWindow1
        Dim PC As New PreviewControl(commandData.Application.ActiveUIDocument.Document, _
                                     commandData.Application.ActiveUIDocument.ActiveGraphicalView.Id)

        PCW.MainGrid.Children.Add(PC)
        PC.SetValue(Controls.Grid.RowProperty, 1)
        PC.SetValue(Controls.Grid.HorizontalAlignmentProperty, HorizontalAlignment.Stretch)
        PC.SetValue(Controls.Grid.VerticalAlignmentProperty, VerticalAlignment.Stretch)
       
        PCW.ShowDialog()

        Return Result.Succeeded
    End Function

 

0 Likes

swfaust
Advocate
Advocate

Interesting that those work, although they are a bit different situations...  ComboBox uses a popup in the template which is technically a different window if I understand correclty.  However it closes as soon as you click anywhere else so it doesn't have to move with the window that contains it.  In this case I need the control to roll out over other items and then stay open until it is closed by the user, so it has to move with the parent window so I'm not sure that would work (although it may be worth experimenting).  I haven't looked at the internals for ToolTip so I don't know if that's another window or not.  To be more specific you should have a grid with two children in the same area and put the preview control first (which would normally put it in the background in WPF) and another control over it.  Preview control will still show up in front.  Something like:

 

<Grid>

    <Grid>**Place Preview Control as a Child of This Grid**</Grid>

    <Rectangle Width="200" Height="200" Fill="Red" />

</Grid>

 

You would expect the red rectangle to be drawn over the preview control based on normal WPF layout rules, but it won't be.

 

Like I said we have it working by revising our UI layout so I'm not going to spend a ton more time on revising it unless it gets in the way again, but bottom line it's not following the layout rules that you would expect in WPF...

0 Likes

FRFR1426
Collaborator
Collaborator

What you're experiencing here is well know and is called the "WPF airspace" problem. Basically it happens when you're hosting Winforms content (the preview control) in a WPF window. You can Google this term to find more explanation and solutions/workarounds.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

guofeng.zhang
Autodesk
Autodesk

Yes.

The preview window is the same as the internal view windows, they are all MFC/Win32 window. It should not be overlapped with WPF canvas. And there's no direct solution for this issue. Microsoft was provided a solution in a beta version of .Net but removed that in the official release.

0 Likes