You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be very helpful to - out of the box - be able to
accept any ContentDialog (i.e. ContentDialogResult.Primary) by pressing Enter (or have some binding that allows to define which key to press) and
being able to cancel any ContentDialog by pressing Escape
This does work if I
add my own focusable content
add event handlers to it
and make sure it is focused
I would also be happy if we could subscribe to the KeyDown event of the ContentDialog
However, on Windows, the KeyDown event is never fired.
Here is my sample that actually works but is a bit complicated IMHO
// for strings, we need to add a TextBlock, since the DataTempalte for strings is - by default - a non-focusable TextBlockvartb=newTextBlock{Text=message,Focusable=true,// set it to focusableIsTabStop=true// and a tab stop};vard=newContentDialog(){Title=title,Content=tb,IsSecondaryButtonEnabled=false,PrimaryButtonText=okButton,CloseButtonText=cancelButton,};// ...subscribe to the keydown events of the _TextBlock_ (!!)tb.KeyDown+=(_,args)=>{if(args.Key==Key.Enter)d.Hide(ContentDialogResult.Primary);if(args.Key==Key.Escape)d.Hide();};// ... and ensure that it is focused when it is attached to the viewtb.AttachedToVisualTree+=(element,args)=>{if(elementisIInputElementi)i.Focus();};varr=awaitd.ShowAsync();
I would prefer this though:
vard=newContentDialog(){Title=title,Content=message,IsSecondaryButtonEnabled=false,PrimaryButtonText=okButton,CloseButtonText=cancelButton,};// ...subscribe to the keydown events of the ContentDialogd.KeyDown+=(_,args)=>{if(args.Key==Key.Enter)d.Hide(ContentDialogResult.Primary);if(args.Key==Key.Escape)d.Hide();};varr=awaitd.ShowAsync();
The text was updated successfully, but these errors were encountered:
Hello!
It would be very helpful to - out of the box - be able to
ContentDialog
(i.e.ContentDialogResult.Primary
) by pressingEnter
(or have some binding that allows to define which key to press) andContentDialog
by pressingEscape
This does work if I
I would also be happy if we could subscribe to the
KeyDown
event of theContentDialog
However, on Windows, the
KeyDown
event is never fired.Here is my sample that actually works but is a bit complicated IMHO
I would prefer this though:
The text was updated successfully, but these errors were encountered: