UWP Titlebar problem

123244 140 Reputation points
2025-08-07T14:41:49.6+00:00

Hello, I had a problem accessing the title bar at UWP. From the code below:

  1. We have MainPopup element which contains content of popups that can be open in the application.
  2. AppTitleBar element is set as titlebar.

When the popup is visible (opened), the window cannot be moved by dragging the title bar. I'm assuming PopupContentBackground covers up AppTitleBar element. No matter where I moved the AppTitleBar element in the visual tree (higher or lower in the markup), it always remained covered by PopupContentBackground when the popup was open.

        					<Popup x:Name="MainPopup"
                                   IsOpen="True"
                                   Grid.Row="0"
                                   HorizontalAlignment="Stretch"
                                   VerticalAlignment="Stretch">
                                <Grid Width = "{Binding Value, Source={StaticResource ActualWindowWidthProxy}}"
                                      Height="{Binding Value, Source={StaticResource ActualWindowHeightProxy}}">
                                    <Grid x:Name="PopupContentBackground"
                                          Visibility="Collapsed"
                                          Background="{ThemeResource PopupShadowBrush}"
                                          HorizontalAlignment="Stretch"
                                          VerticalAlignment="Stretch" />
                                    <ContentControl x:Name="PopupContentControl"
                                                    Visibility="Collapsed"
                                                    VerticalContentAlignment="Stretch"
                                                    HorizontalContentAlignment="Stretch"
                                                    HorizontalAlignment="Stretch"
                                                    VerticalAlignment="Stretch" />
                                </Grid>
                            </Popup>
                            <Grid x:Name="AppTitleBar"
                                  Background="Red"
                                  Margin="50,0,0,0"
                                  VerticalAlignment="Top">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition x:Name="LeftPaddingColumn"
                                                      Width="0" />
                                    <ColumnDefinition />
                                    <ColumnDefinition x:Name="RightPaddingColumn"
                                                      Width="0" />
                                </Grid.ColumnDefinitions>
                                <TextBlock Text = "{Binding ApplicationName, Source={StaticResource Locator}}"
                                           Foreground="{ThemeResource TextColor}"
                                           Grid.Column="1"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Center"
                                           FontSize="12"
                                           Margin="12,0,0,0" />
                            </Grid>

To resolve this issue I used code below:

                Window.Current.SetTitleBar(new ApplicationTitleBar());

Instead of using AppTitleBar element, I created a new UIelement inside the initialization method. In this case, the title bar is always available, even if a pop-up is open. I couldn't understand or find why and how this actually works. So I ask for an explanation if you can find or provide one.

From the AI response below, it seems that when creating an element in the method , its XamlRoot is not bound to the parent element, so it somehow appeared above all other elements. If you know what caused this behavior, please let us know.

Developer technologies | Universal Windows Platform (UWP)
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Harry Vo (WICLOUD CORPORATION) 405 Reputation points Microsoft External Staff
    2025-08-12T03:53:15.56+00:00

    Hi @123244 ,

    My name is Harry, Support Engineer who specialize in UWP (Universal Windows Platform). Thank you for reaching out on Microsoft Q&A! Let me help clarify what’s happening in your scenario and why you’re seeing this behavior.

    In UWP, the Popup control is designed to render in a dedicated visual layer above the main content of your app. This ensures that the popup captures focus and interaction until it’s closed. Because your custom title bar (AppTitleBar) is defined inside the main page layout, it sits underneath this overlay layer. So when the popup opened, it's totally normal if you cannot click or drag your title bar until the popup is closed.

    If your requirement is to allow interaction with both at the same time, you would need to use a separate window rather than a popup. You can learn more about creating additional windows here: Create and display multiple views.


    Regarding your second approach using:

    Window.Current.SetTitleBar(new ApplicationTitleBar());
    

    This works differently because the element you pass to SetTitleBar is not inserted into your page’s visual tree. Instead, it is registered directly with the windowing system as the drag region for the entire app window. This bypasses normal hit-testing rules in the XAML layer, so even if another UI element (like your popup) is visually on top of that area, the OS still recognizes it as a draggable region.

    It’s important to note that SetTitleBar does not create a new titlebar , it just forces an element acts as titlebar. It also have to be given an element that looks like a title bar. It can be any UIElement — a rectangle, a button, or even part of your main content — and the OS will treat that area as the draggable zone for the entire window. In your case, you’ve chosen to pass a title bar element, so the behavior matches a traditional window title bar. For example:

    • You could pass a Grid at the bottom of the window, making the window draggable from the bottom edge.
    • You could pass an invisible rectangle in the middle of your content to allow dragging from that spot.
    • You could combine a visible title bar with other draggable regions elsewhere in your UI.

    I hope this clarifies why your XAML-defined title bar is blocked by the popup and why the SetTitleBar approach works. If my explaination helpful, feel free to interact with the system accordingly!

    Thank you!

    0 comments No comments

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.