I want to have a button with a higher z order than hwndHost in wpf.

Fayyaaz 01 25 Reputation points
2023-03-02T13:45:59.77+00:00

I want to have a button with a higher z order than hwndHost in wpf. Changing the z index in grid, panel and canvas did not work. Sources found in msdn documents state the hosted window in hwndHost will always stay on top of other WPF elements in the same top-level window and even on top adorner elements. Here, are the sources i refered.

1)https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/layout-considerations-for-the-windowsformshost-element?redirectedfrom=MSDN&view=netframeworkdesktop-4.8

2)https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-3.0/ms742522(v=vs.85)?redirectedfrom=MSDN

I want to know if these sources are outdated. And if there is any other way to have a ui element like button on top of the hwndHost.

I want to know if there is any way to acheive the below idea. The purpose of that button is to show or hide Menu. I feel using popups may complicate things for my requirement. Is there any other way or popup is my only goto?


<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <Menu Grid.Column="0" />

    <ContentControl Grid.Column="1" Content={"Binding HostedWindow"} Grid.ZIndex="0">
        
    </ContentControl>
    
    <Button Grid.Column="1" Content="Show Menu" Click="ShowMenu_Click" Grid.ZIndex="1"/>
    
</Grid>
Developer technologies | Windows Presentation Foundation
Developer technologies | XAML
Developer technologies | C#
0 comments No comments
{count} vote

Accepted answer
  1. Jack J Jun 25,296 Reputation points
    2023-03-03T07:00:08.79+00:00

    @Fayyaaz 01, Welcome to Microsoft Q&A, based on my research, I find that we still could not set a higher order than hwndHost in wpf.

    However, I find a workaround to help to solve your problem. We could try to use AirspacePopup to do it.

    Please refer to the answer from the stack overflow, which has a completed code example.

    Hope my workaround could help you.

    Best Regards,

    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.