feat: add recall as internal function to overlay dialog.

This commit is contained in:
rabbitism
2024-03-09 18:52:26 +08:00
parent 04305234a1
commit 51d7c3c870
5 changed files with 30 additions and 3 deletions

View File

@@ -48,5 +48,8 @@
</Border> </Border>
</Grid> </Grid>
<TextBox u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></TextBox> <TextBox u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></TextBox>
<TextBox u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></TextBox>
<TextBox u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></TextBox>
<u:NumericIntUpDown u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></u:NumericIntUpDown>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

View File

@@ -212,5 +212,11 @@ public static class OverlayDialog
control.CanDragMove = options.CanDragMove; control.CanDragMove = options.CanDragMove;
} }
internal static T? Recall<T>(string? hostId) where T: Control
{
var host = OverlayDialogManager.GetHost(hostId);
if (host is null) return null;
var item = host.Recall<T>();
return item;
}
} }

View File

@@ -54,6 +54,13 @@ public class NumPad: TemplatedControl
private static void OnTargetGotFocus(object sender, GotFocusEventArgs e) private static void OnTargetGotFocus(object sender, GotFocusEventArgs e)
{ {
if (sender is not InputElement) return;
var existing = OverlayDialog.Recall<NumPad>(null);
if (existing is not null)
{
existing.Target = sender as InputElement;
return;
}
var numPad = new NumPad() { Target = sender as InputElement }; var numPad = new NumPad() { Target = sender as InputElement };
OverlayDialog.ShowCustom(numPad, new object()); OverlayDialog.ShowCustom(numPad, new object());
} }

View File

@@ -216,6 +216,11 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
} }
protected override void OnTextInput(TextInputEventArgs e)
{
_textBox?.RaiseEvent(e);
}
private void OnDragPanelPointerReleased(object sender, PointerReleasedEventArgs e) private void OnDragPanelPointerReleased(object sender, PointerReleasedEventArgs e)
{ {
_point = null; _point = null;

View File

@@ -189,4 +189,10 @@ public partial class OverlayDialogHost: Canvas
} }
return result; return result;
} }
internal T? Recall<T>()
{
var element = _layers.LastOrDefault(a => a.Element.Content?.GetType() == typeof(T));
return element?.Element.Content is T t ? t : default;
}
} }