ContentDialog 模板


    

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

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

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

一个魔法
IsPrimaryButtonEnabled="{Binding ElementName=ApiKey, Path=Text.Length}"

一些基础属性
CloseButtonText="Close"
PrimaryButtonText="Save"
DefaultButton="Primary"

注意ContentDialog需要考虑键盘按键 ESC Enter 键的穿越性,需结合IsPrimaryButtonEnabled状态

你可能感兴趣的:(ContentDialog 模板)