Skip to content

Comments

ContentDialog.DefaultButton should accepts only Button.IsEnabled = true#311

Merged
Kinnara merged 1 commit intoKinnara:masterfrom
msmcjp:master
May 28, 2022
Merged

ContentDialog.DefaultButton should accepts only Button.IsEnabled = true#311
Kinnara merged 1 commit intoKinnara:masterfrom
msmcjp:master

Conversation

@atsusy
Copy link
Contributor

@atsusy atsusy commented Mar 20, 2021

No description provided.

@AlphaNecron
Copy link

You can use Command...

@atsusy
Copy link
Contributor Author

atsusy commented Apr 12, 2021

<ui:ContentDialog x:Class="ModernWPFUITest.TestContentDialog"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:ModernWPFUITest"
             mc:Ignorable="d" 
             IsPrimaryButtonEnabled="False"
             PrimaryButtonText="OK"     
             DefaultButton="Primary"
             xmlns:ui="http://schemas.modernwpf.com/2019">
    <Grid>
            
    </Grid>
</ui:ContentDialog>

Show ContentDialog above, hit enter key then ContentDialog will close.

@AlphaNecron
Copy link

Create a custom command and set CanExecute

@atsusy
Copy link
Contributor Author

atsusy commented Apr 13, 2021

@AlphaNecron

Thank you for your comment.

UWP's ContentDialog does not accept Enter key with the code above.

This behavior is not safe for users. I hope this pullrequest is merged.

@atsusy
Copy link
Contributor Author

atsusy commented Apr 13, 2021

<ui:ContentDialog x:Class="ModernWPFUITest.TestContentDialog"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:ModernWPFUITest"
             mc:Ignorable="d" 
             IsPrimaryButtonEnabled="False"
             PrimaryButtonText="OK"    
             SecondaryButtonText="Cancel"
             DefaultButton="Primary"
             xmlns:ui="http://schemas.modernwpf.com/2019">
    <Grid>
        <TextBox />
    </Grid>
</ui:ContentDialog>

In this case, hit Enter key then result is Primary.

@AlphaNecron
Copy link

How about catching KeyDown event and use this.Hide();?

@luojunyuan
Copy link

Guys I use this workaround to deal with ESC, Enter key when dialog closing.

public partial class XXXDialog : ContentDialog
{
    public XXXDialog()
    {
            InitializeComponent();

            PrimaryButtonClick += (_, _) =>
            {
                // Condition here cause "Enter" key would cross this
                if (IsPrimaryButtonEnabled)
                {
                    ;
                }
            };

            Closing += (_, args) =>
            {
                // If the PrimaryButton is disabled, block the "Enter" key
                if (args.Result == ContentDialogResult.Primary && !IsPrimaryButtonEnabled)
                {
                    args.Cancel = true;
                }
            };
    }
}

@Kinnara Kinnara merged commit 4b8da0b into Kinnara:master May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants