从其他窗口将新项添加到列表框中

时间:2013-07-08 09:52:34

标签: c# wpf textbox save listboxitem

在我的wpf应用程序中,我创建了两个视图类,DayView和CustomView。在DayView中,有一个由一些条目组成的列表框。在列表框中,有一个包含5个文本框的stackpanel。在我的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]: http://i.stack.imgur.com/1Qi0e.png

这是CustomView窗口!

[2]: http://i.stack.imgur.com/mACxR.png

1 个答案:

答案 0 :(得分:0)

在我看来,更适合使用mvvm框架来使您的解决方案更具结构性,然后使用Messenger在您的视图之间进行通信。