0

Because of this question I know how to set the focus of a Control (Windows.UI.Xaml.Controls.Control); however, I do not know how to get access to the ContentDialog's SeocndaryButton in order to set it's focus. This is not the same as setting it as the DefaultButton. When I do that I still cannot just hit enter to activate the secondary button.

Does anyone know how to do this?

UnskilledBuild
  • 264
  • 1
  • 3
  • 12

2 Answers2

1

It's possible for you to think about using custom dialog instead of using the default button. You can have a look at this case. In general, when you customize your own buttons, you can add the functions you want to these buttons to have your own logic. Does this make sense to you?(I've tested with custom buttons' focus and it works)

Barry Wang
  • 1,459
  • 1
  • 8
  • 12
  • Thank you for your answer! That is indeed the correct way to go about it. My ContentDialog however was so tightly coupled I couldn't "roll my own" buttons without doing some more work. At some point in the project I will come back to it and do it right. For now though, your answer is the most correct as far as I can tell. That is, unless Microsoft wants to add a getter for the primary and secondary buttons :) – UnskilledBuild Feb 06 '19 at 20:45
0

For now I could only come up with a workaround. I wanted the enter key to do the same as if I hit the secondaryButton. When I overrode the enter key it never dismissed the dialog, but!!! If I added a hide to it, it seems to work as intended. I would like to know how to give it focus, but this will work for now.

protected override void OnKeyUp(KeyRoutedEventArgs e)
    {
        base.OnKeyUp(e);
        if (e.Key == Windows.System.VirtualKey.Enter)
        {
            ContentDialog_SecondaryButtonClick(null, null);
            this.Hide();
        }
    }
UnskilledBuild
  • 264
  • 1
  • 3
  • 12