-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TopMost handling for Popups on Windows #17841
Open
StefanKoell
wants to merge
4
commits into
AvaloniaUI:master
Choose a base branch
from
StefanKoell:fix-popup-topmost-windows
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+142
−2
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
be8c413
Fix TopMost handling for Popups on Windows
StefanKoell 477a956
Properly handle TopMost property changes
StefanKoell ce2525b
Call SetTopMost in PopupRoot constructor (similar to SetWindowManager…
StefanKoell 8961609
Make sure the parent is focused when the popup is clicked directly to…
StefanKoell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<UserControl x:Class="ControlCatalog.Pages.PopupsPage" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | ||
|
||
<StackPanel Orientation="Vertical" Spacing="10"> | ||
|
||
<TextBlock Text="'Light Dismiss' Popup" /> | ||
<Button Content="Show Popup" Click="ButtonLightDismiss_OnClick" /> | ||
|
||
<TextBlock Text="Popup that stays open" /> | ||
<Button Content="Show Popup" Click="ButtonPopupStaysOpen_OnClick" /> | ||
|
||
<TextBlock Text="TopMost popup that stays open" /> | ||
<Button Content="Show Popup" Click="ButtonTopMostPopupStaysOpen" /> | ||
|
||
</StackPanel> | ||
|
||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.Primitives; | ||
using Avalonia.Controls.Primitives.PopupPositioning; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Layout; | ||
using Avalonia.Markup.Xaml; | ||
using Avalonia.Media; | ||
|
||
namespace ControlCatalog.Pages; | ||
|
||
public class PopupsPage : UserControl | ||
{ | ||
private Popup? _popup; | ||
private Popup? _topMostPopup; | ||
public PopupsPage() | ||
{ | ||
InitializeComponent(); | ||
|
||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
private void ButtonLightDismiss_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
new Popup | ||
{ | ||
Placement = PlacementMode.Bottom, | ||
PlacementTarget = sender as Button, | ||
Child = new Panel { Margin = new Thickness(10) ,Children = { new TextBlock { Text = "Popup Content" } }}, | ||
IsLightDismissEnabled = true, | ||
IsOpen = true | ||
}; | ||
} | ||
|
||
private void ButtonPopupStaysOpen_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
if (_popup is not null) | ||
return; | ||
|
||
var closeButton = new Button { Content = "Click to Close" }; | ||
closeButton.Click += (o, args) => | ||
{ | ||
if (_popup is null) | ||
return; | ||
|
||
LogicalChildren.Remove(_popup); | ||
_popup.IsOpen = false; | ||
_popup = null; | ||
}; | ||
_popup = new Popup | ||
{ | ||
Placement = PlacementMode.Bottom, | ||
PlacementTarget = sender as Button, | ||
Child = new StackPanel | ||
{ | ||
Spacing = 10, | ||
Margin = new Thickness(10), | ||
Orientation = Orientation.Vertical, | ||
Children = | ||
{ | ||
new TextBox | ||
{ | ||
Width = 100, | ||
Text = "Some text", | ||
}, | ||
new TextBox | ||
{ | ||
Width = 100, | ||
Text = "Some other text", | ||
}, | ||
closeButton | ||
} | ||
}, | ||
IsLightDismissEnabled = false, | ||
}; | ||
|
||
LogicalChildren.Add(_popup); | ||
_popup.IsOpen = true; | ||
} | ||
|
||
private void ButtonTopMostPopupStaysOpen(object sender, RoutedEventArgs e) | ||
{ | ||
if (_topMostPopup is not null) | ||
return; | ||
|
||
var closeButton = new Button { Content = "Click to Close" }; | ||
closeButton.Click += (o, args) => | ||
{ | ||
if (_topMostPopup is null) | ||
return; | ||
_topMostPopup.IsOpen = false; | ||
_topMostPopup = null; | ||
}; | ||
_topMostPopup = new Popup | ||
{ | ||
Placement = PlacementMode.Bottom, | ||
PlacementTarget = sender as Button, | ||
Child = new Panel | ||
{ | ||
Margin = new Thickness(10), Children = { closeButton } | ||
}, | ||
IsLightDismissEnabled = false, | ||
Topmost = true, | ||
IsOpen = true | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,8 +53,7 @@ protected override IntPtr CreateWindowOverride(ushort atom) | |
UnmanagedMethods.WindowStyles.WS_CLIPCHILDREN; | ||
|
||
UnmanagedMethods.WindowStyles exStyle = | ||
UnmanagedMethods.WindowStyles.WS_EX_TOOLWINDOW | | ||
UnmanagedMethods.WindowStyles.WS_EX_TOPMOST; | ||
UnmanagedMethods.WindowStyles.WS_EX_TOOLWINDOW; | ||
|
||
var result = UnmanagedMethods.CreateWindowEx( | ||
(int)exStyle, | ||
|
@@ -84,6 +83,10 @@ protected override IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr l | |
_maxAutoSize = null; | ||
goto default; | ||
case UnmanagedMethods.WindowsMessage.WM_MOUSEACTIVATE: | ||
if (_parent?.Handle is not null) | ||
{ | ||
UnmanagedMethods.SetFocus(_parent.Handle.Handle); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maxkatz6 found an issue with focus management. I'm not sure if this is the correct way to handle it but if I don't set the focus to the parent when the popup is clicked, I'm not able to type in the popup if there's a textbox, for example. |
||
} | ||
return (IntPtr)UnmanagedMethods.MouseActivate.MA_NOACTIVATE; | ||
default: | ||
return base.WndProc(hWnd, msg, wParam, lParam); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These testing buttons can be moved to the IntegrationTestApp. I can try to add integration test on top of them later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could use some guidance on this one. Not sure what I should do 😳