Skip to content

Commit

Permalink
DYN-7523: editwindow fix (DynamoDS#15615)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnenov authored Nov 7, 2024
1 parent 2f20dee commit 7f40772
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/DynamoCoreWpf/UI/Prompts/EditWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ public EditWindow(DynamoViewModel dynamoViewModel,

Owner = dynamoViewModel.Owner;
this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
this.Loaded += (sender, e) => this.editText.Focus();

// Center the window again once rendering is complete
this.ContentRendered += (sender, e) =>
{
this.Left = Owner.Left + (Owner.Width - this.ActualWidth) / 2;
this.Top = Owner.Top + (Owner.Height - this.ActualHeight) / 2;
};

// do not accept value if user closes
this.Closing += (sender, args) => this.DialogResult = false;
Expand All @@ -57,8 +49,28 @@ public EditWindow(DynamoViewModel dynamoViewModel,
}
this.editText.PreviewKeyDown += EditText_PreviewKeyDown;
this.Closed += EditWindow_Closed;
this.ContentRendered += OnContentRendered;
}

// Centralize the window correctly after it is rendered
private void OnContentRendered(object sender, EventArgs e)
{
// Unsubscribe immediately, we only call this once on initialization
this.ContentRendered -= OnContentRendered;

CenterWindowRelativeToOwner();
editText.Focus();
}

// Centralize the window relative to another Window
private void CenterWindowRelativeToOwner()
{
if (Owner != null)
{
this.Left = Owner.Left + (Owner.Width - this.ActualWidth) / 2;
this.Top = Owner.Top + (Owner.Height - this.ActualHeight) / 2;
}
}

private void CloseButton_OnClick(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -105,9 +117,6 @@ private void ToggleButtons(bool toggle)

private void EditText_PreviewKeyDown(object sender, KeyEventArgs e)
{
var textBox = sender as TextBox;
var caretIndex = textBox.CaretIndex;

EditTextBoxPreviewKeyDown?.Invoke(sender, e);
}

Expand Down

0 comments on commit 7f40772

Please sign in to comment.