Pressing a key in ContentDialog












0















So I have a Button in Xaml:



    <Button x:Name="btnCancel"
Click="btnCancel_Click"
Content="Cancel"></Button>


and in a ContentDialog I want to press a Key to trigger that button. My Problem is that no key presses are recognized and I don´t understand why.



.cs:



public sealed partial class MyDialog : ContentDialog
{
public MyDialog()
{
this.InitializeComponent();
this.Loaded += MyDialog_Loaded;

this.Closing += ContentDialog_Closing;
this.KeyDown += onE_KeyDown;
}

//...

private void onE_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Escape)
{
//btnCancel_Click(sender, e);
btnCancel_Click(this, new RoutedEventArgs());
}
}

void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
args.Cancel = syncInProcess;
// btnCancel_Click(this, new RoutedEventArgs());
}
}


I put a breakpoint at the onE_KeyDown method but it never gets there.










share|improve this question



























    0















    So I have a Button in Xaml:



        <Button x:Name="btnCancel"
    Click="btnCancel_Click"
    Content="Cancel"></Button>


    and in a ContentDialog I want to press a Key to trigger that button. My Problem is that no key presses are recognized and I don´t understand why.



    .cs:



    public sealed partial class MyDialog : ContentDialog
    {
    public MyDialog()
    {
    this.InitializeComponent();
    this.Loaded += MyDialog_Loaded;

    this.Closing += ContentDialog_Closing;
    this.KeyDown += onE_KeyDown;
    }

    //...

    private void onE_KeyDown(object sender, KeyRoutedEventArgs e)
    {
    if (e.Key == Windows.System.VirtualKey.Escape)
    {
    //btnCancel_Click(sender, e);
    btnCancel_Click(this, new RoutedEventArgs());
    }
    }

    void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
    {
    args.Cancel = syncInProcess;
    // btnCancel_Click(this, new RoutedEventArgs());
    }
    }


    I put a breakpoint at the onE_KeyDown method but it never gets there.










    share|improve this question

























      0












      0








      0








      So I have a Button in Xaml:



          <Button x:Name="btnCancel"
      Click="btnCancel_Click"
      Content="Cancel"></Button>


      and in a ContentDialog I want to press a Key to trigger that button. My Problem is that no key presses are recognized and I don´t understand why.



      .cs:



      public sealed partial class MyDialog : ContentDialog
      {
      public MyDialog()
      {
      this.InitializeComponent();
      this.Loaded += MyDialog_Loaded;

      this.Closing += ContentDialog_Closing;
      this.KeyDown += onE_KeyDown;
      }

      //...

      private void onE_KeyDown(object sender, KeyRoutedEventArgs e)
      {
      if (e.Key == Windows.System.VirtualKey.Escape)
      {
      //btnCancel_Click(sender, e);
      btnCancel_Click(this, new RoutedEventArgs());
      }
      }

      void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
      {
      args.Cancel = syncInProcess;
      // btnCancel_Click(this, new RoutedEventArgs());
      }
      }


      I put a breakpoint at the onE_KeyDown method but it never gets there.










      share|improve this question














      So I have a Button in Xaml:



          <Button x:Name="btnCancel"
      Click="btnCancel_Click"
      Content="Cancel"></Button>


      and in a ContentDialog I want to press a Key to trigger that button. My Problem is that no key presses are recognized and I don´t understand why.



      .cs:



      public sealed partial class MyDialog : ContentDialog
      {
      public MyDialog()
      {
      this.InitializeComponent();
      this.Loaded += MyDialog_Loaded;

      this.Closing += ContentDialog_Closing;
      this.KeyDown += onE_KeyDown;
      }

      //...

      private void onE_KeyDown(object sender, KeyRoutedEventArgs e)
      {
      if (e.Key == Windows.System.VirtualKey.Escape)
      {
      //btnCancel_Click(sender, e);
      btnCancel_Click(this, new RoutedEventArgs());
      }
      }

      void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
      {
      args.Cancel = syncInProcess;
      // btnCancel_Click(this, new RoutedEventArgs());
      }
      }


      I put a breakpoint at the onE_KeyDown method but it never gets there.







      c# uwp keydown






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 7:49









      axbeitaxbeit

      14110




      14110
























          3 Answers
          3






          active

          oldest

          votes


















          1














          If KeyDown event never fires, chances are that the control handles it internally. MSDN says:




          Specific Windows Runtime controls may have class-based handling for the KeyDown input event. If so, the control probably has an override for the method OnKeyDown. Typically these class handlers are intended to process a subset of key presses that enable a keyboard-based user interaction with that control, and often this interaction supports a keyboard accessibility feature. If a key press is handled by class-based handling, then the key press is considered to be already handled, and the KeyDown event is not raised for handling by any user code handlers on that control for that key specifically.




          If that's the case you can try overwrite OnKeyDown method to change this behaviour. Unfortunately I can't check now if that's really the problem but maybe this will help you.






          share|improve this answer































            0














            Try to use CoreWindow.KeyDown Event instead:



            Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
            //this.KeyDown += MyDialog_KeyDown;


            In addition, if you do not consider the case where the keyboard is not released for a long time, try to use KeyUp event which can be fired normally.



            By the way, the Esc key of the keyboard will close the ContentDialog by default, so you need to prevent this feature first in the Closing event.



            The compete code:



            public MyDialog()
            {
            this.InitializeComponent();
            this.Loaded += MyDialog_Loaded;

            this.Closing += ContentDialog_Closing;
            //this.KeyDown += onE_KeyDown;
            this.KeyUp += MyDialog_KeyUp;
            }

            private void MyDialog_KeyUp(object sender, KeyRoutedEventArgs e)
            {
            if (e.Key == Windows.System.VirtualKey.Escape)
            {
            //btnCancel_Click(sender, e);
            btnCancel_Click(this, new RoutedEventArgs());
            }
            }

            void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
            {
            //args.Cancel = syncInProcess;
            // btnCancel_Click(this, new RoutedEventArgs());
            if (args.Result == ContentDialogResult.None)
            {
            args.Cancel = true;
            }
            }





            share|improve this answer































              0














              The event you are looking for is PreviewKeyDown event. Keydown event will not get fired if that particular key is handled by system default. PreviewKeyDown fires in all cases.



              Note: make sure you set e.handled = false for remaining keys



              https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.uielement.previewkeydown



               <ContentDialog
              x:Class="App1.NewContentDialog"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:local="using:App1"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              mc:Ignorable="d"
              Title="TITLE"
              PreviewKeyDown="ContentDialog_PreviewKeyDown"
              PrimaryButtonText="Button1"
              SecondaryButtonText="Button2"
              PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
              SecondaryButtonClick="ContentDialog_SecondaryButtonClick">

              <Grid>
              </Grid>
              </ContentDialog>


              private void ContentDialog_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
              {
              if (e.Key == Windows.System.VirtualKey.Escape)
              {
              btnCancel_Click(this, new RoutedEventArgs());
              }
              else
              {
              e.Handled = false;
              }
              }





              share|improve this answer























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276175%2fpressing-a-key-in-contentdialog%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1














                If KeyDown event never fires, chances are that the control handles it internally. MSDN says:




                Specific Windows Runtime controls may have class-based handling for the KeyDown input event. If so, the control probably has an override for the method OnKeyDown. Typically these class handlers are intended to process a subset of key presses that enable a keyboard-based user interaction with that control, and often this interaction supports a keyboard accessibility feature. If a key press is handled by class-based handling, then the key press is considered to be already handled, and the KeyDown event is not raised for handling by any user code handlers on that control for that key specifically.




                If that's the case you can try overwrite OnKeyDown method to change this behaviour. Unfortunately I can't check now if that's really the problem but maybe this will help you.






                share|improve this answer




























                  1














                  If KeyDown event never fires, chances are that the control handles it internally. MSDN says:




                  Specific Windows Runtime controls may have class-based handling for the KeyDown input event. If so, the control probably has an override for the method OnKeyDown. Typically these class handlers are intended to process a subset of key presses that enable a keyboard-based user interaction with that control, and often this interaction supports a keyboard accessibility feature. If a key press is handled by class-based handling, then the key press is considered to be already handled, and the KeyDown event is not raised for handling by any user code handlers on that control for that key specifically.




                  If that's the case you can try overwrite OnKeyDown method to change this behaviour. Unfortunately I can't check now if that's really the problem but maybe this will help you.






                  share|improve this answer


























                    1












                    1








                    1







                    If KeyDown event never fires, chances are that the control handles it internally. MSDN says:




                    Specific Windows Runtime controls may have class-based handling for the KeyDown input event. If so, the control probably has an override for the method OnKeyDown. Typically these class handlers are intended to process a subset of key presses that enable a keyboard-based user interaction with that control, and often this interaction supports a keyboard accessibility feature. If a key press is handled by class-based handling, then the key press is considered to be already handled, and the KeyDown event is not raised for handling by any user code handlers on that control for that key specifically.




                    If that's the case you can try overwrite OnKeyDown method to change this behaviour. Unfortunately I can't check now if that's really the problem but maybe this will help you.






                    share|improve this answer













                    If KeyDown event never fires, chances are that the control handles it internally. MSDN says:




                    Specific Windows Runtime controls may have class-based handling for the KeyDown input event. If so, the control probably has an override for the method OnKeyDown. Typically these class handlers are intended to process a subset of key presses that enable a keyboard-based user interaction with that control, and often this interaction supports a keyboard accessibility feature. If a key press is handled by class-based handling, then the key press is considered to be already handled, and the KeyDown event is not raised for handling by any user code handlers on that control for that key specifically.




                    If that's the case you can try overwrite OnKeyDown method to change this behaviour. Unfortunately I can't check now if that's really the problem but maybe this will help you.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 14 '18 at 14:04









                    MailoszMailosz

                    6417




                    6417

























                        0














                        Try to use CoreWindow.KeyDown Event instead:



                        Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
                        //this.KeyDown += MyDialog_KeyDown;


                        In addition, if you do not consider the case where the keyboard is not released for a long time, try to use KeyUp event which can be fired normally.



                        By the way, the Esc key of the keyboard will close the ContentDialog by default, so you need to prevent this feature first in the Closing event.



                        The compete code:



                        public MyDialog()
                        {
                        this.InitializeComponent();
                        this.Loaded += MyDialog_Loaded;

                        this.Closing += ContentDialog_Closing;
                        //this.KeyDown += onE_KeyDown;
                        this.KeyUp += MyDialog_KeyUp;
                        }

                        private void MyDialog_KeyUp(object sender, KeyRoutedEventArgs e)
                        {
                        if (e.Key == Windows.System.VirtualKey.Escape)
                        {
                        //btnCancel_Click(sender, e);
                        btnCancel_Click(this, new RoutedEventArgs());
                        }
                        }

                        void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
                        {
                        //args.Cancel = syncInProcess;
                        // btnCancel_Click(this, new RoutedEventArgs());
                        if (args.Result == ContentDialogResult.None)
                        {
                        args.Cancel = true;
                        }
                        }





                        share|improve this answer




























                          0














                          Try to use CoreWindow.KeyDown Event instead:



                          Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
                          //this.KeyDown += MyDialog_KeyDown;


                          In addition, if you do not consider the case where the keyboard is not released for a long time, try to use KeyUp event which can be fired normally.



                          By the way, the Esc key of the keyboard will close the ContentDialog by default, so you need to prevent this feature first in the Closing event.



                          The compete code:



                          public MyDialog()
                          {
                          this.InitializeComponent();
                          this.Loaded += MyDialog_Loaded;

                          this.Closing += ContentDialog_Closing;
                          //this.KeyDown += onE_KeyDown;
                          this.KeyUp += MyDialog_KeyUp;
                          }

                          private void MyDialog_KeyUp(object sender, KeyRoutedEventArgs e)
                          {
                          if (e.Key == Windows.System.VirtualKey.Escape)
                          {
                          //btnCancel_Click(sender, e);
                          btnCancel_Click(this, new RoutedEventArgs());
                          }
                          }

                          void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
                          {
                          //args.Cancel = syncInProcess;
                          // btnCancel_Click(this, new RoutedEventArgs());
                          if (args.Result == ContentDialogResult.None)
                          {
                          args.Cancel = true;
                          }
                          }





                          share|improve this answer


























                            0












                            0








                            0







                            Try to use CoreWindow.KeyDown Event instead:



                            Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
                            //this.KeyDown += MyDialog_KeyDown;


                            In addition, if you do not consider the case where the keyboard is not released for a long time, try to use KeyUp event which can be fired normally.



                            By the way, the Esc key of the keyboard will close the ContentDialog by default, so you need to prevent this feature first in the Closing event.



                            The compete code:



                            public MyDialog()
                            {
                            this.InitializeComponent();
                            this.Loaded += MyDialog_Loaded;

                            this.Closing += ContentDialog_Closing;
                            //this.KeyDown += onE_KeyDown;
                            this.KeyUp += MyDialog_KeyUp;
                            }

                            private void MyDialog_KeyUp(object sender, KeyRoutedEventArgs e)
                            {
                            if (e.Key == Windows.System.VirtualKey.Escape)
                            {
                            //btnCancel_Click(sender, e);
                            btnCancel_Click(this, new RoutedEventArgs());
                            }
                            }

                            void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
                            {
                            //args.Cancel = syncInProcess;
                            // btnCancel_Click(this, new RoutedEventArgs());
                            if (args.Result == ContentDialogResult.None)
                            {
                            args.Cancel = true;
                            }
                            }





                            share|improve this answer













                            Try to use CoreWindow.KeyDown Event instead:



                            Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
                            //this.KeyDown += MyDialog_KeyDown;


                            In addition, if you do not consider the case where the keyboard is not released for a long time, try to use KeyUp event which can be fired normally.



                            By the way, the Esc key of the keyboard will close the ContentDialog by default, so you need to prevent this feature first in the Closing event.



                            The compete code:



                            public MyDialog()
                            {
                            this.InitializeComponent();
                            this.Loaded += MyDialog_Loaded;

                            this.Closing += ContentDialog_Closing;
                            //this.KeyDown += onE_KeyDown;
                            this.KeyUp += MyDialog_KeyUp;
                            }

                            private void MyDialog_KeyUp(object sender, KeyRoutedEventArgs e)
                            {
                            if (e.Key == Windows.System.VirtualKey.Escape)
                            {
                            //btnCancel_Click(sender, e);
                            btnCancel_Click(this, new RoutedEventArgs());
                            }
                            }

                            void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
                            {
                            //args.Cancel = syncInProcess;
                            // btnCancel_Click(this, new RoutedEventArgs());
                            if (args.Result == ContentDialogResult.None)
                            {
                            args.Cancel = true;
                            }
                            }






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 10 '18 at 9:37









                            Stanly FanStanly Fan

                            11




                            11























                                0














                                The event you are looking for is PreviewKeyDown event. Keydown event will not get fired if that particular key is handled by system default. PreviewKeyDown fires in all cases.



                                Note: make sure you set e.handled = false for remaining keys



                                https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.uielement.previewkeydown



                                 <ContentDialog
                                x:Class="App1.NewContentDialog"
                                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                                xmlns:local="using:App1"
                                xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                                mc:Ignorable="d"
                                Title="TITLE"
                                PreviewKeyDown="ContentDialog_PreviewKeyDown"
                                PrimaryButtonText="Button1"
                                SecondaryButtonText="Button2"
                                PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
                                SecondaryButtonClick="ContentDialog_SecondaryButtonClick">

                                <Grid>
                                </Grid>
                                </ContentDialog>


                                private void ContentDialog_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
                                {
                                if (e.Key == Windows.System.VirtualKey.Escape)
                                {
                                btnCancel_Click(this, new RoutedEventArgs());
                                }
                                else
                                {
                                e.Handled = false;
                                }
                                }





                                share|improve this answer




























                                  0














                                  The event you are looking for is PreviewKeyDown event. Keydown event will not get fired if that particular key is handled by system default. PreviewKeyDown fires in all cases.



                                  Note: make sure you set e.handled = false for remaining keys



                                  https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.uielement.previewkeydown



                                   <ContentDialog
                                  x:Class="App1.NewContentDialog"
                                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                                  xmlns:local="using:App1"
                                  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                                  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                                  mc:Ignorable="d"
                                  Title="TITLE"
                                  PreviewKeyDown="ContentDialog_PreviewKeyDown"
                                  PrimaryButtonText="Button1"
                                  SecondaryButtonText="Button2"
                                  PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
                                  SecondaryButtonClick="ContentDialog_SecondaryButtonClick">

                                  <Grid>
                                  </Grid>
                                  </ContentDialog>


                                  private void ContentDialog_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
                                  {
                                  if (e.Key == Windows.System.VirtualKey.Escape)
                                  {
                                  btnCancel_Click(this, new RoutedEventArgs());
                                  }
                                  else
                                  {
                                  e.Handled = false;
                                  }
                                  }





                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    The event you are looking for is PreviewKeyDown event. Keydown event will not get fired if that particular key is handled by system default. PreviewKeyDown fires in all cases.



                                    Note: make sure you set e.handled = false for remaining keys



                                    https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.uielement.previewkeydown



                                     <ContentDialog
                                    x:Class="App1.NewContentDialog"
                                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                                    xmlns:local="using:App1"
                                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                                    mc:Ignorable="d"
                                    Title="TITLE"
                                    PreviewKeyDown="ContentDialog_PreviewKeyDown"
                                    PrimaryButtonText="Button1"
                                    SecondaryButtonText="Button2"
                                    PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
                                    SecondaryButtonClick="ContentDialog_SecondaryButtonClick">

                                    <Grid>
                                    </Grid>
                                    </ContentDialog>


                                    private void ContentDialog_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
                                    {
                                    if (e.Key == Windows.System.VirtualKey.Escape)
                                    {
                                    btnCancel_Click(this, new RoutedEventArgs());
                                    }
                                    else
                                    {
                                    e.Handled = false;
                                    }
                                    }





                                    share|improve this answer













                                    The event you are looking for is PreviewKeyDown event. Keydown event will not get fired if that particular key is handled by system default. PreviewKeyDown fires in all cases.



                                    Note: make sure you set e.handled = false for remaining keys



                                    https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.uielement.previewkeydown



                                     <ContentDialog
                                    x:Class="App1.NewContentDialog"
                                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                                    xmlns:local="using:App1"
                                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                                    mc:Ignorable="d"
                                    Title="TITLE"
                                    PreviewKeyDown="ContentDialog_PreviewKeyDown"
                                    PrimaryButtonText="Button1"
                                    SecondaryButtonText="Button2"
                                    PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
                                    SecondaryButtonClick="ContentDialog_SecondaryButtonClick">

                                    <Grid>
                                    </Grid>
                                    </ContentDialog>


                                    private void ContentDialog_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
                                    {
                                    if (e.Key == Windows.System.VirtualKey.Escape)
                                    {
                                    btnCancel_Click(this, new RoutedEventArgs());
                                    }
                                    else
                                    {
                                    e.Handled = false;
                                    }
                                    }






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Dec 10 '18 at 9:54









                                    VigneshVignesh

                                    831316




                                    831316






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276175%2fpressing-a-key-in-contentdialog%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Full-time equivalent

                                        Bicuculline

                                        さくらももこ