将新项目从其他窗口添加到列表框中
本文关键字:列表 添加 窗口 新项目 其他 | 更新日期: 2023-09-27 18:21:32
在我的wpf应用程序中,我创建了两个视图类,DayView和CustomView。在DayView中,有一个由一些条目组成的列表框。在列表框中,有一个包含5个文本框的堆叠面板。在我的CustomView类中,我还创建了带有5个文本框的stackpanel。当我在CustomView的文本框中输入数据并单击保存按钮时,新条目应该创建,数据应该保存在DayView的相应文本框中。
CustomView类:
namespace TimeSheet
{
/// <summary>
/// Interaction logic for CustomView.xaml
/// </summary>
public partial class CustomView : Window
{
public List<Harvest_Project> projectList { get; set; }
public List<Harvest_Client> clientList { get; set; }
public Harvest_Project selectedProjectid { get; set; }
public Harvest_Client selectedClientid { get; set; }
private string client { get { return ClientText.Text; } set { ClientText.Text=value;} }
private string application { get { return ApplicationText.Text; } set { ApplicationText.Text = value; } }
private string starttime { get { return StartTimeText.Text; } set { StartTimeText.Text = value; } }
private string stoptime { get { return StopTimeText.Text; } set { StopTimeText.Text = value; } }
private string task { get { return TaskText.Text; } set { TaskText.Text = value; } }
private string project { get { return ProjectText.Text; } set { ProjectText.Text = value; } }
public CustomView()
{
InitializeComponent();
this.DataContext = this;
Globals._globalController.setCustomViewWindow(this);
clientList = Globals._globalController.harvestManager._CLIENTLIST;
projectList = Globals._globalController.harvestManager._PROJECTLIST;
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
if (sender is Harvest_TimeSheetEntry)
{
//Harvest_TimeSheetEntry entry = new Harvest_TimeSheetEntry();
//if (!entry.isSynced)
//{
// entry.ClientNameBinding = client;
// entry.ApplicationNameBinding = application;
// entry.StartTimeBinding = starttime;
// entry.StopTimeBinding = stoptime;
// entry.TaskNameBinding = task;
// entry.ProjectNameBinding = project;
//}
Globals._globalController.getDayViewWindow.Show();
this.Hide();
}
}
private void ClientComboBoxChanged(object sender, SelectionChangedEventArgs e)
{
string text = (sender as ComboBox).SelectedItem.ToString();
}
private void ProjectComboBoxChanged(object sender, SelectionChangedEventArgs e)
{
string text = (sender as ComboBox).SelectedItem.ToString();
}
}
}
我不明白,我应该如何在DayView列表框中保存这些数据。请提出一些方法。!
这是DayView窗口
[1]: https://i.stack.imgur.com/1Qi0e.png
这是CustomView窗口!
[2]: https://i.stack.imgur.com/mACxR.png
在我看来,使用mvvm框架使您的解决方案更加结构化,然后使用Messenger在您的视图之间进行通信更合适。