Merge pull request #771 from yangjieshao/DialogControlClosed
增强 OverlayDialog 和 NumPad 的功能与交互体验
This commit is contained in:
@@ -66,4 +66,8 @@ public class OverlayDialogOptions
|
|||||||
public bool CanResize { get; set; }
|
public bool CanResize { get; set; }
|
||||||
|
|
||||||
public string? StyleClass { get; set; }
|
public string? StyleClass { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// </summary>
|
||||||
|
internal Delegate? OnDialogControlClosed { set; get; }
|
||||||
}
|
}
|
||||||
@@ -34,10 +34,22 @@ public static class OverlayDialog
|
|||||||
DataContext = vm,
|
DataContext = vm,
|
||||||
};
|
};
|
||||||
ConfigureDefaultDialogControl(t, options);
|
ConfigureDefaultDialogControl(t, options);
|
||||||
|
|
||||||
|
if (options?.OnDialogControlClosed != null)
|
||||||
|
{
|
||||||
|
t.AddHandler(OverlayShared.OverlayFeedbackElement.ClosedEvent, options.OnDialogControlClosed);
|
||||||
|
|
||||||
|
t.AddHandler(OverlayShared.OverlayFeedbackElement.ClosedEvent, (s, _) =>
|
||||||
|
{
|
||||||
|
if (s is not DialogControlBase dc) return;
|
||||||
|
dc.RemoveHandler(OverlayShared.OverlayFeedbackElement.ClosedEvent, options.OnDialogControlClosed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
host.AddDialog(t);
|
host.AddDialog(t);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Show(object? vm, string? hostId = null, OverlayDialogOptions? options = null)
|
public static void Show(object? vm, string? hostId = null, OverlayDialogOptions? options = null)
|
||||||
{
|
{
|
||||||
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
var host = OverlayDialogManager.GetHost(hostId, options?.TopLevelHashCode);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class NumPad: TemplatedControl
|
|||||||
GotFocusEvent.RemoveHandler(OnTargetGotFocus, input);
|
GotFocusEvent.RemoveHandler(OnTargetGotFocus, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnTargetGotFocus(object? sender, GotFocusEventArgs e)
|
private static void OnTargetGotFocus(object? sender, GotFocusEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is not InputElement) return;
|
if (sender is not InputElement) return;
|
||||||
@@ -75,12 +75,19 @@ public class NumPad: TemplatedControl
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var numPad = new NumPad()
|
var numPad = new NumPad()
|
||||||
{
|
{
|
||||||
Target = sender as InputElement ,
|
Target = sender as InputElement ,
|
||||||
_targetInnerText = FindTextBoxInTarget((sender as InputElement)!)
|
_targetInnerText = FindTextBoxInTarget((sender as InputElement)!)
|
||||||
};
|
};
|
||||||
OverlayDialog.Show(numPad, new object(), options: new OverlayDialogOptions() { Buttons = DialogButton.None });
|
OverlayDialog.Show(numPad, new object(), options: new OverlayDialogOptions()
|
||||||
|
{
|
||||||
|
Buttons = DialogButton.None,
|
||||||
|
OnDialogControlClosed = (object? ss, object? e) =>
|
||||||
|
{
|
||||||
|
numPad.Target?.Focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Dictionary<Key, string> KeyInputMapping = new()
|
private static readonly Dictionary<Key, string> KeyInputMapping = new()
|
||||||
@@ -138,7 +145,7 @@ public class NumPad: TemplatedControl
|
|||||||
// 如果目标本身就是 TextBox
|
// 如果目标本身就是 TextBox
|
||||||
if (target is TextBox textBox)
|
if (target is TextBox textBox)
|
||||||
return textBox;
|
return textBox;
|
||||||
|
|
||||||
// 如果目标是 TemplatedControl,并且已经应用了模板
|
// 如果目标是 TemplatedControl,并且已经应用了模板
|
||||||
if (target is TemplatedControl templatedControl && templatedControl.IsInitialized)
|
if (target is TemplatedControl templatedControl && templatedControl.IsInitialized)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user