Have a look at this simple bit of code:

...
Dim result As ContentDialogResult = Await cldEdit.ShowAsync()
If result = ContentDialogResult.Primary Then
	DoTextChange()
End If
...

Looks pretty straight forward? If the content dialog return result is that the primary button has been pressed then call DoTextChange().

That all works well if the users presses the primary button but what happens if you want your dialog control to act like a standard WinForms dialog and accept Enter or Cancel keyboard presses to close the content dialog?

Have a look at this code:

Private Sub txtEdit_KeyUp(sender As Object, e As KeyRoutedEventArgs)
	Select Case e.Key
		Case Windows.System.VirtualKey.Enter
			If cldEdit.IsPrimaryButtonEnabled Then
				cldEdit.Hide()
			End If
		Case Windows.System.VirtualKey.Escape
			cldEdit.Hide()
	End Select
End Sub

Looks good? Nope! Hiding the content dialog doesn’t return a result so the initial code we had won’t work and our sub DoTextChange() won’t get called.

So how do you force the content dialog to return a result? The short answer is you can’t but if you change your approach you can achieve what you want.

The trick is to ignore the result completely and process the event of the button itself. Do this:

'display the dialog, don't worry about the result returned
...
Await cldEdit.ShowAsync()
...

Add in the event handler for your primary button on your content dialog

Private Sub cldEdit_PrimaryButtonClick(sender As ContentDialog, args As ContentDialogButtonClickEventArgs)
	DoTextChange()
End Sub

And add in the call DoTextChange() to your KeyUp event

Private Sub txtEdit_KeyUp(sender As Object, e As KeyRoutedEventArgs)
	Select Case e.Key
		Case Windows.System.VirtualKey.Enter
			If cldEdit.IsPrimaryButtonEnabled Then
				cldEdit.Hide()
				DoTextChange()
			End If
		Case Windows.System.VirtualKey.Escape
			cldEdit.Hide()
	End Select
End Sub