-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInputWindow.xaml.cs
More file actions
55 lines (49 loc) · 1.75 KB
/
InputWindow.xaml.cs
File metadata and controls
55 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Windows;
namespace XColumn
{
/// <summary>
/// ユーザーにテキスト入力を促すためのシンプルなダイアログウィンドウ。
/// </summary>
public partial class InputWindow : Window
{
/// <summary>
/// ユーザーが入力して「OK」を押したテキストを取得します。
/// </summary>
public string? InputText { get; private set; }
/// <summary>
/// InputWindow のコンストラクタ。
/// </summary>
/// <param name="title">ウィンドウのタイトル</param>
/// <param name="prompt">説明文</param>
/// <param name="defaultText">テキストボックスの初期値(省略可)</param>
public InputWindow(string title, string prompt, string defaultText = "")
{
InitializeComponent();
this.Title = title;
PromptTextBlock.Text = prompt;
// 初期値をセット
InputTextBox.Text = defaultText;
// 入力しやすいように全選択状態にする
if (!string.IsNullOrEmpty(defaultText))
{
InputTextBox.SelectAll();
}
}
/// <summary>
/// ウィンドウがロードされた時、自動的にフォーカスを当てます。
/// </summary>
private void Window_Loaded(object? sender, RoutedEventArgs e)
{
InputTextBox.Focus();
}
/// <summary>
/// OKボタン処理
/// </summary>
private void OkButton_Click(object? sender, RoutedEventArgs e)
{
InputText = InputTextBox.Text;
this.DialogResult = true;
this.Close();
}
}
}