-
-
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
be8c413
477a956
ce2525b
8961609
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.Primitives; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Markup.Xaml; | ||
|
||
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; | ||
_popup.IsOpen = false; | ||
_popup = null; | ||
}; | ||
_popup = new Popup | ||
{ | ||
Placement = PlacementMode.Bottom, | ||
PlacementTarget = sender as Button, | ||
Child = new Panel | ||
{ | ||
Margin = new Thickness(10), Children = { closeButton } | ||
}, | ||
IsLightDismissEnabled = false, | ||
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 | ||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -154,7 +154,11 @@ void IPopupHost.ConfigurePosition(PopupPositionRequest request) | |||
UpdatePosition(); | ||||
} | ||||
|
||||
public void SetChild(Control? control) => Content = control; | ||||
public void SetChild(Control? control) | ||||
{ | ||||
PlatformImpl?.SetTopmost(Topmost); | ||||
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. Feels a bit wrong to do anything unrelated to 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. Yeah, I wasn't sure about that one. The TopMost property is set in the line above in Popup.cs, so I thought setting the TopMost here would be least intrusive. Changing and affecting the property at runtime would need to handle it in 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. Check the last commit: Seems to work and doesn't feel "wrong" anymore? 😅 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. Popup already has OnPropertyChanged for Topmost:
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. As for PopupRoot, probably mirror behavior of WindowShadowHint property? 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. @StefanKoell just noticed newer commit. Yes, that's much better. 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. Got it! Should now work pretty much the same as with WindowShadowHint. |
||||
Content = control; | ||||
} | ||||
|
||||
public void TakeFocus() => PlatformImpl?.TakeFocus(); | ||||
|
||||
|
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 😳