There was a need to create a window for entering the file name which will be created later. Creating a window is easy, but I cannot think of how to return data from this window. Is there any way to determine if a Click() event has occurred Or tell me more competent or reasonable ways. I would be glad even to the direction in which to look.
The code for the window being created:
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(); } } Calling this window:
public void GetFileName() { var InputBoxMsg = "Enter you file name"; InputBox inputBox = new InputBox(); inputBox.Show(InputBoxMsg); }