0

在我的 wpf 应用程序中,我创建了两个视图类,DayView 和 CustomView。在 DayView 中,有一个由一些条目组成的列表框。在列表框中,有一个带有 5 个文本框的堆栈面板。在我的 CustomView 类中,我还创建了带有 5 个文本框的堆栈面板。当我将数据输入到 CustomView 的这些文本框中并单击保存按钮时,应创建新条目并将数据保存在 DayView 的相应文本框中。

自定义视图类:

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

这是自定义视图窗口!

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

1 回答 1

0

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

于 2013-07-08T10:03:02.903 回答