using System.Windows.Controls; using System.Windows.Input; namespace WpfApp1 { using System.Windows; /// /// Interaction logic for DialogFrame.xaml /// public partial class DialogFrame { private Point? _mousePointOnClick; public DialogFrame(string title, string message) { InitializeComponent(); this.TitleBlock.Text = title; this.MessageBlock.Text = message; SetMouseStatus(); } private void CloseDialog_OnClick(object sender, RoutedEventArgs e) { DialogService.Instance.Remove(this); } private void NewDialog_OnClick(object sender, RoutedEventArgs e) { DialogService.Instance.Add( new DialogFrame("Child", $"Child dialog {DialogService.Instance.Dialogs.Count}") ); } private void Border_OnMouseDown(object sender, MouseButtonEventArgs e) { var thisPosition = e.GetPosition(this); _mousePointOnClick = new Point( thisPosition.X - BorderTransform.X, thisPosition.Y - BorderTransform.Y ); SetMouseStatus(); } private void Border_OnMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed && _mousePointOnClick is { } pointOnClick) { var pos = e.GetPosition(this); BorderTransform.X = pos.X - pointOnClick.X; BorderTransform.Y = pos.Y - pointOnClick.Y; } SetMouseStatus(); } private void Border_OnMouseUp(object sender, MouseButtonEventArgs e) { _mousePointOnClick = null; SetMouseStatus(); } private void SetMouseStatus() { MouseStatus.Text = $"""PointOnClick:"{(_mousePointOnClick?.ToString() ?? "")}", BorderTransform:"{BorderTransform.X:F1}:{BorderTransform.Y:F1}" """; } private void DialogFrame_OnKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) { DialogService.Instance.Remove(this); } } } }