Close the content dialog in code.

I have a content dialog with a text box, and I would like to close the dialog box when I press Enter in the text box. Is there a way to achieve this without pressing the main button?

+4
source share
2 answers

ContentDialog.Hide () hides the dialog, after which the ShowAsync call is returned. I can not guarantee that the call will be the same with the main button, but this is enough for me. :)

https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.contentdialog.hide

+5
source

The trap I hit responded to ContentDialogResult as follows:

    ContentDialogResult result = await cldEdit.ShowAsync();
    if (result == ContentDialogResult.Primary)
    {
        DoTextChange();
    }

Instead, ignore the result and call your event-based function.

, KeyUp PrimaryButtonClick:

private void txtEdit_KeyUp(object sender, KeyRoutedEventArgs e)
{
    switch (e.Key) {
        case Windows.System.VirtualKey.Enter:
            if (cldEdit.IsPrimaryButtonEnabled) {
                cldEdit.Hide();
                DoTextChange();
            }
            break;
        case Windows.System.VirtualKey.Escape:
            cldEdit.Hide();
            break;
    }

}

private void cldEdit_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
    DoTextChange();
}
0

Source: https://habr.com/ru/post/1618150/


All Articles