Visual Studio / WPF > 確認ダイアログ > アイコン表示 | デフォルトボタン


動作環境
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community

以下の機能を持つ確認ダイアログを表示する。

  • アイコン (?や!など)
  • デフォルトボタン

MessageBox.Show()で処理するようだ。

MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace _170612_t1213_messageDialog
{
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void uxConfirm_Click(object sender, RoutedEventArgs e)
        {

            string msg = "";
            msg += "Is it OK?" + "\r\n";
            msg += "Away team" + "\r\n";
            msg += "1. Janeway" + "\r\n";
            msg += "2. Tuvok" + "\r\n";
            msg += "3. Chakotay";

            MessageBoxResult res = MessageBox.Show(msg, "Confirmation", MessageBoxButton.OKCancel, 
                MessageBoxImage.Question, MessageBoxResult.Cancel);
            switch (res)
            {
                case MessageBoxResult.OK:
                    // OKの処理
                    break;
                case MessageBoxResult.Cancel:
                    // Cancelの処理
                    break;
            }
        }
    }
}
MainWindow.xaml
<Window x:Class="_170612_t1213_messageDialog.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:_170612_t1213_messageDialog"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button x:Name="uxConfirm" Content="確認" Height="28" Width="100"
                Click="uxConfirm_Click"/>
    </Grid>
</Window>

検索用キーワード

C++ Builderのメッセージボックスと関連した検索キーワード。

  • mtInformation
  • mtConfirmation