103 lines
2.9 KiB
C#
103 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
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.Shapes;
|
|
|
|
namespace ILSOS_KS.Views.Dialog
|
|
{
|
|
/// <summary>
|
|
/// InputWindow.xaml에 대한 상호 작용 논리
|
|
/// </summary>
|
|
public partial class InputWindow : Window, INotifyPropertyChanged
|
|
{
|
|
public string InputValue { get; private set; }
|
|
|
|
// INotifyPropertyChanged 구현
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
protected void OnPropertyChanged(string name)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
|
}
|
|
|
|
|
|
private string _windowTitle;
|
|
public string WindowTitle
|
|
{
|
|
get => _windowTitle;
|
|
set
|
|
{
|
|
_windowTitle = value;
|
|
OnPropertyChanged(nameof(WindowTitle));
|
|
}
|
|
}
|
|
|
|
private string _inputLabel;
|
|
public string InputLabel
|
|
{
|
|
get => string.IsNullOrEmpty(_inputLabel) ? "Please enter only numbers" : _inputLabel;
|
|
set
|
|
{
|
|
_inputLabel = value;
|
|
OnPropertyChanged(nameof(InputLabel));
|
|
}
|
|
}
|
|
|
|
public InputWindow(string windowTitle, string inputLabel)
|
|
{
|
|
InitializeComponent();
|
|
WindowTitle = windowTitle;
|
|
InputLabel = inputLabel;
|
|
}
|
|
|
|
private void Confirm_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
InputValue = InputTextBox.Text;
|
|
DialogResult = true; // 창 닫힘
|
|
}
|
|
|
|
private void Cancel_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
DialogResult = false;
|
|
}
|
|
|
|
// 숫자 입력만 허용 (키보드 입력)
|
|
private void InputTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
|
{
|
|
e.Handled = !IsTextNumeric(e.Text);
|
|
}
|
|
// 숫자 입력만 허용 (붙여넣기)
|
|
private void InputTextBox_Pasting(object sender, DataObjectPastingEventArgs e)
|
|
{
|
|
if (e.DataObject.GetDataPresent(DataFormats.Text))
|
|
{
|
|
string text = e.DataObject.GetData(DataFormats.Text) as string;
|
|
if (!IsTextNumeric(text))
|
|
{
|
|
e.CancelCommand(); // 붙여넣기 차단
|
|
}
|
|
}
|
|
else
|
|
{
|
|
e.CancelCommand();
|
|
}
|
|
}
|
|
|
|
// 숫자인지 검사하는 메서드
|
|
private bool IsTextNumeric(string text)
|
|
{
|
|
return Regex.IsMatch(text, "^[0-9]+$");
|
|
}
|
|
}
|
|
}
|