Я получил две сцены (окна): «MainWindow.xaml.cs» и «SecondaryWindow.xaml.cs».У меня также есть один класс "Control.cs".
Я пытаюсь объявить 2 разных List<string>
и 2 public string
в моем классе Control.cs.Это выглядит следующим образом.
class Control
{
}
public class MyControl
{
List<string> NameList = new List<string>();
List<string> DescriptionList = new List<string>();
public string Name {
get { return Name; }
set { Name = value; }
}
public string Description {
get { return Description; }
set { Description = value; }
}
}
Я хочу получить доступ к различным строкам из Control.cs в моем классе SecondWindow.xaml.cs, чтобы я мог дать им каждому значение из 2 текстовых полей в SecondWindow.
После этого я хочу сохранить строку Name
в NameList
и строку Description
в DescriptionList
.
Затем я отправлю Name
в ListBox в "MainWindow", гдея думаю, что это можно было бы добавить как-то так ..?
private void Button_SaveAndReturn(object sender, RoutedEventArgs e)
{
var main = (MainWindow)Application.Current.MainWindow;
if (Example.Name != "" && Example.Description != "")
{
DateTime now = DateTime.Now;
main.listBox.Items.Add(string.Format("{0}: {1} ", Example.name, now));
this.Close();
}
Я стараюсь изо всех сил выдать как можно больше подробностей, скажите, есть ли что-то еще, что вам нужно!Заранее спасибо.
Редактировать
Вот мой Контроль Класс:
class Control
{
List<string> NameList = new List<string>();
List<string> DescriptionList = new List<string>();
public static string Name
{
get { return Name; }
set { Name = value; }
}
public static string Description
{
get { return Description; }
set { Description = value; }
}
}
И мой основной класс
private void Button_SaveAndReturn(object sender, RoutedEventArgs e)
{
List<string> nameList = new List<string>();
List<string> descriptionList = new List<string>();
var name = Control.Name;
var desc = Control.Description;
var main = (MainWindow)Application.Current.MainWindow;
if (name != "" && desc !="")
{
nameList.Add(name);
descriptionList.Add(desc);
DateTime now = DateTime.Now;
main.listBox.Items.Add(string.Format("{0}: {1} ", name, now));
this.Close();
}
else if (name== "")
{
MessageBox.Show("Please enter a name", "Name Error", MessageBoxButton.OK, MessageBoxImage.Error);
this.NameInput.Focus();
}
else
{
MessageBox.Show("Please enter some text", "Text Error", MessageBoxButton.OK, MessageBoxImage.Error);
this.TextInput.Focus();
}