问题
I am trying to convert my Winforms application to WPF format, I am trying to convert the double click of my listview at the moment. I have done this so far:
private void listView1_DoubleClick(object sender, MouseButtonEventArgs e)
{
ListViewItem item = this.listView1.SelectedItems[0];
if (item.Tag != null)
{
ControllerInfo controllerInfo = (ControllerInfo)item.Tag;
if (controllerInfo.Availability == Availability.Available)
{
if (controllerInfo.IsVirtual)
{
this.controller = ControllerFactory.CreateFrom(controllerInfo);
this.controller.Logon(UserInfo.DefaultUser);
listView1.Items.Clear();
listView1.Items.Add(item);
EnableControllerFunctionality();
}
else //real controller
{
if (MessageBox.Show("This is NOT a virtual controller, do you really want to connect to that?","Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
this.controller = ControllerFactory.CreateFrom(controllerInfo);
this.controller.Logon(UserInfo.DefaultUser);
listView1.Items.Clear();
listView1.Items.Add(item);
EnableControllerFunctionality();
}
}
}
else
{
MessageBox.Show("Selected controller not available.");
}
}
The problem is with the first line :
ListViewItem item = this.listView1.SelectedItems[0];
stating 'cannot implicitly convert from object to listviewitem. An explicit conversion exists I have been trying to find this conversion but to no avail. I feel as though I am missing something key.
来源:https://stackoverflow.com/questions/23654281/convert-object-to-listviewitem