|
@@ -134,6 +134,12 @@ namespace Avalonia.Controls.Primitives
|
|
public static readonly StyledProperty<bool> TopmostProperty =
|
|
public static readonly StyledProperty<bool> TopmostProperty =
|
|
AvaloniaProperty.Register<Popup, bool>(nameof(Topmost));
|
|
AvaloniaProperty.Register<Popup, bool>(nameof(Topmost));
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Defines the <see cref="TakesFocusFromNativeControl"/> property.
|
|
|
|
+ /// </summary>
|
|
|
|
+ public static readonly AttachedProperty<bool> TakesFocusFromNativeControlProperty =
|
|
|
|
+ AvaloniaProperty.RegisterAttached<Popup, Control, bool>(nameof(TakesFocusFromNativeControl), true);
|
|
|
|
+
|
|
private bool _isOpenRequested;
|
|
private bool _isOpenRequested;
|
|
private bool _ignoreIsOpenChanged;
|
|
private bool _ignoreIsOpenChanged;
|
|
private PopupOpenState? _openState;
|
|
private PopupOpenState? _openState;
|
|
@@ -364,6 +370,23 @@ namespace Avalonia.Controls.Primitives
|
|
set => SetValue(TopmostProperty, value);
|
|
set => SetValue(TopmostProperty, value);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets or sets a value indicating whether the popup, on show, transfers focus from any
|
|
|
|
+ /// focused native control to Avalonia. The default is <c>true</c>.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <remarks>
|
|
|
|
+ /// This property only applies to advanced native control embedding scenarios. By default,
|
|
|
|
+ /// if a popup is shown when a native control is focused, focus is transferred back to
|
|
|
|
+ /// Avalonia in order for the popup to receive input. If this property is set to
|
|
|
|
+ /// <c>false</c>, then the shown popup will not receive input until it receives an
|
|
|
|
+ /// interaction which explicitly focuses the popup, such as a mouse click.
|
|
|
|
+ /// </remarks>
|
|
|
|
+ public bool TakesFocusFromNativeControl
|
|
|
|
+ {
|
|
|
|
+ get => GetValue(TakesFocusFromNativeControlProperty);
|
|
|
|
+ set => SetValue(TakesFocusFromNativeControlProperty, value);
|
|
|
|
+ }
|
|
|
|
+
|
|
IPopupHost? IPopupHostProvider.PopupHost => Host;
|
|
IPopupHost? IPopupHostProvider.PopupHost => Host;
|
|
|
|
|
|
event Action<IPopupHost?>? IPopupHostProvider.PopupHostChanged
|
|
event Action<IPopupHost?>? IPopupHostProvider.PopupHostChanged
|
|
@@ -520,6 +543,9 @@ namespace Avalonia.Controls.Primitives
|
|
|
|
|
|
popupHost.Show();
|
|
popupHost.Show();
|
|
|
|
|
|
|
|
+ if (TakesFocusFromNativeControl)
|
|
|
|
+ popupHost.TakeFocus();
|
|
|
|
+
|
|
using (BeginIgnoringIsOpen())
|
|
using (BeginIgnoringIsOpen())
|
|
{
|
|
{
|
|
SetCurrentValue(IsOpenProperty, true);
|
|
SetCurrentValue(IsOpenProperty, true);
|
|
@@ -535,6 +561,27 @@ namespace Avalonia.Controls.Primitives
|
|
/// </summary>
|
|
/// </summary>
|
|
public void Close() => CloseCore();
|
|
public void Close() => CloseCore();
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets the value of the <see cref="TakesFocusFromNativeControl"/> attached property on the
|
|
|
|
+ /// specified control.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="control">The control.</param>
|
|
|
|
+ public static bool GetTakesFocusFromNativeControl(Control control)
|
|
|
|
+ {
|
|
|
|
+ return control.GetValue(TakesFocusFromNativeControlProperty);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Sets the value of the <see cref="TakesFocusFromNativeControl"/> attached property on the
|
|
|
|
+ /// specified control.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="control">The control.</param>
|
|
|
|
+ /// <param name="value">The value of the TakesFocusFromNativeControl property.</param>
|
|
|
|
+ public static void SetTakesFocusFromNativeControl(Control control, bool value)
|
|
|
|
+ {
|
|
|
|
+ control.SetValue(TakesFocusFromNativeControlProperty, value);
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Measures the control.
|
|
/// Measures the control.
|
|
/// </summary>
|
|
/// </summary>
|