コード例 #1
0
        /// <summary>
        /// 删除按钮被点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            var p = vm.PersonOnDisplay;

            var contentPanel  = new StackPanel();
            var nameTextBlock = new TextBlock()
            {
                Text = string.Format(ResourceLoader.GetString("DeletePersonDialog_Content_Name"), p.Name)
            };
            var studentNumberTextBlock = new TextBlock()
            {
                Text = string.Format(ResourceLoader.GetString("DeletePersonDialog_Content_StudentNumber"), p.StudentNumber)
            };

            contentPanel.Children.Insert(0, nameTextBlock);
            contentPanel.Children.Insert(1, studentNumberTextBlock);
            contentPanel.Orientation = Orientation.Vertical;

            ContentDialog dialog = new ContentDialog()
            {
                Content             = contentPanel,
                Title               = ResourceLoader.GetString("DeletePersonDialog_Title"),
                PrimaryButtonText   = ResourceLoader.GetString("DeletePersonDialog_PrimaryButtonText"),
                SecondaryButtonText = ResourceLoader.GetString("DeletePersonDialog_SecondaryButtonText"),
                //DefaultButton = ContentDialogButton.Primary
            };

            ContentDialogResult result = await dialog.ShowAsync();

            switch (result)
            {
            case ContentDialogResult.Primary:
                if (await vm.DeletePersonOnDisplay())
                {
                    await new ContentDialog()
                    {
                        Title             = ResourceLoader.GetString("DeletePersonSuccessDialog_Title"),
                        PrimaryButtonText = ResourceLoader.GetString("DeletePersonSuccessDialog_PrimaryButtonText"),
                        //DefaultButton = ContentDialogButton.Primary
                    }.ShowAsync();
                }
                else
                {
                    await new ContentDialog()
                    {
                        Content           = ResourceLoader.GetString("DeletePersonFailDialog_Content"),
                        Title             = ResourceLoader.GetString("DeletePersonFailDialog_Title"),
                        PrimaryButtonText = ResourceLoader.GetString("DeletePersonFailDialog_PrimaryButtonText"),
                        //DefaultButton = ContentDialogButton.Primary
                    }.ShowAsync();
                }
                break;

            default:
                break;
            }
        }