【问题标题】:Add new Item to the listbox from other window从其他窗口将新项目添加到列表框
【发布时间】:2013-07-08 09:52:34
【问题描述】:

在我的 wpf 应用程序中,我创建了两个视图类,DayView 和 CustomView。在 DayView 中,有一个由一些条目组成的列表框。在列表框中,有一个带有 5 个文本框的堆栈面板。在我的 CustomView 类中,我还创建了带有 5 个文本框的堆栈面板。当我将数据输入到 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

【问题讨论】:

    标签: c# wpf textbox save listboxitem


    【解决方案1】:

    在我看来,使用 mvvm 框架使您的解决方案更有条理,然后使用 Messenger 在您的视图之间进行交流更合适。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      • 2014-11-06
      相关资源
      最近更新 更多