Возникла необходимость создавать окно для ввода названия файла который позже будет создан. Создать окно несложно, но как от этого окна вернуть данные я не могу придумать. Есть ли способ определить произошло ли событие Click()
? Или подскажите более грамотные или разумные способы. Буду рад даже направлению в котором искать.
Код создаваемого окна:
class InputBox : Window
{
//private static InputBoxDialog;
private static TextBox textBox;
private static Button button;
private static Label label;
private static Window NewWindow;
private static Window CurrentWindow;
private static string TextVar;
public InputBox()
{
}
public InputBox(ref Window textVar)
{
}
public void Show(string labelContent)
{
CreateBox(labelContent);
}
public void Show(string labelContent, string titleContent)
{
CreateBox(labelContent, titleContent);
}
public void Show(string labelContent, string titleContent, string buttonContent)
{
CreateBox(labelContent, titleContent, buttonContent);
}
private void CreateBox(string labelContent, string titleContent = "Input Box", string buttonContent = "Enter")
{
NewWindow = new Window();
NewWindow.Name = "NewWindow";
NewWindow.Title = titleContent;
NewWindow.Width = 300;
NewWindow.Height = 200;
var stackPanel = new StackPanel { Orientation = Orientation.Vertical };
label = new Label { Content = labelContent, Name = "NewWindowLabel" };
textBox = new TextBox { Text = "", Name = "NewWindowTextBox" };
button = new Button { Content = buttonContent, Name = "NewWindowButton" };
button.Click += NewWindowButton_Click;
stackPanel.Children.Add(label);
stackPanel.Children.Add(textBox);
stackPanel.Children.Add(button);
NewWindow.Content = stackPanel;
NewWindow.Show();
}
private void NewWindowButton_Click(object sender, RoutedEventArgs e)
{
TextVar = textBox.Text;
NewWindow.Close();
}
}
Вызов этого окна:
public void GetFileName()
{
var InputBoxMsg = "Enter you file name";
InputBox inputBox = new InputBox();
inputBox.Show(InputBoxMsg);
}