【发布时间】:2016-01-11 13:59:35
【问题描述】:
我在 Winforms 中编写了一个 C# 应用程序,现在正在 WPF 中重写它。在 Winforms 版本中,我使用以下命令打开另一个窗口,同时向其发送信息并从中接收信息:
using (showSelection showSelection1 = new showSelection(listBox2.SelectedItem.ToString()))
{
showSelection1.ShowDialog();
storage1.showID = showSelection1.showID;
storage1.numOfSeasons = showSelection1.numOfSeasons;
}
这很好,我从 listBox2 发送了选定的项目,并在 showSelection 表单中使用此代码收到了 showID 和 numOfSeasons:
this.showID = Convert.ToInt32(dataGridView1[2, dataGridView1.CurrentCell.RowIndex].Value);
this.numOfSeasons = dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value.ToString();
this.Close();
现在,在 WPF 版本中,我尝试了同样的事情:
using (ShowSelection showSelection = new ShowSelection(showListBox.SelectedItem.ToString()))
{
}
但是在using( ) 里面我得到了这个错误:
ShowSelection: type used in a using statement must be implicitly convertible to 'System.IDisposable'
我不确定从这里到哪里。我可以解决这个问题并且仍然以同样的方式去做,还是有不同的方式我应该这样做? ShowSelection 窗口只是一个带有单个按钮的数据网格。
【问题讨论】:
-
你的 ShowSelection 窗口没有实现 IDispoable,在后面的窗口代码中实现 IDisposable。见stackoverflow.com/questions/4450904/…
-
不要像编写 winforms 那样编写 wpf... 你会错过所有好东西。