我写了一个Winforms的C#应用程序,现在正在重写为WPF。在Winforms版本中,我使用以下方法打开另一个窗口,同时向其发送信息并从其接收信息:
using (showSelection showSelection1 = new showSelection(listBox2.SelectedItem.ToString()))
{
showSelection1.ShowDialog();
storage1.showID = showSelection1.showID;
storage1.numOfSeasons = showSelection1.numOfSeasons;
}
这个很好,我使用showSelection表单中的以下代码从listBox2中发送了所选项目,并接收到了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窗口只是带有单个按钮的数据网格。