feat: ensure dual mode event handling. ensure async command is closed.
This commit is contained in:
@@ -36,7 +36,7 @@
|
|||||||
<TextBlock Text="GotFocus to open, LostFocus to close" Margin="0 16" />
|
<TextBlock Text="GotFocus to open, LostFocus to close" Margin="0 16" />
|
||||||
<u:PopConfirm PopupHeader="确定是否要保存此修改?"
|
<u:PopConfirm PopupHeader="确定是否要保存此修改?"
|
||||||
PopupContent="此修改将不可逆"
|
PopupContent="此修改将不可逆"
|
||||||
TriggerMode="Focus"
|
TriggerMode="Focus, Click"
|
||||||
HorizontalAlignment="Left"
|
HorizontalAlignment="Left"
|
||||||
Placement="{Binding #placement.Value}"
|
Placement="{Binding #placement.Value}"
|
||||||
u:ControlClassesInput.Source="{Binding #classInput}"
|
u:ControlClassesInput.Source="{Binding #classInput}"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
@@ -190,7 +191,7 @@ public class PopConfirm : ContentControl
|
|||||||
void OnCanExecuteChanged(object? _, System.EventArgs a)
|
void OnCanExecuteChanged(object? _, System.EventArgs a)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
if (count < 1) return;
|
if (count < 2) return;
|
||||||
var canExecute = command.CanExecute(button.CommandParameter);
|
var canExecute = command.CanExecute(button.CommandParameter);
|
||||||
if (canExecute)
|
if (canExecute)
|
||||||
{
|
{
|
||||||
@@ -246,8 +247,14 @@ public class PopConfirm : ContentControl
|
|||||||
SetCurrentValue(IsDropdownOpenProperty, false);
|
SetCurrentValue(IsDropdownOpenProperty, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool _suppressButtonClickEvent;
|
||||||
private void OnMainElementGotFocus(object sender, GotFocusEventArgs e)
|
private void OnMainElementGotFocus(object sender, GotFocusEventArgs e)
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine("Got Focus");
|
||||||
|
if (TriggerMode.HasFlag(PopConfirmTriggerMode.Click) && TriggerMode.HasFlag(PopConfirmTriggerMode.Focus))
|
||||||
|
{
|
||||||
|
_suppressButtonClickEvent = true;
|
||||||
|
}
|
||||||
SetCurrentValue(IsDropdownOpenProperty, true);
|
SetCurrentValue(IsDropdownOpenProperty, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +269,12 @@ public class PopConfirm : ContentControl
|
|||||||
|
|
||||||
private void OnMainButtonClicked(object sender, RoutedEventArgs e)
|
private void OnMainButtonClicked(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
SetCurrentValue(IsDropdownOpenProperty, !IsDropdownOpen);
|
Debug.WriteLine("Main Button Clicked");
|
||||||
|
if (!_suppressButtonClickEvent)
|
||||||
|
{
|
||||||
|
SetCurrentValue(IsDropdownOpenProperty, !IsDropdownOpen);
|
||||||
|
}
|
||||||
|
_suppressButtonClickEvent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user