0
我有這些方法。我可以雙擊收藏列表視圖中的一個項目,並且Double_Click方法會觸發並收到消息框。我無法弄清楚的是如何傳遞項目本身,以便我可以訪問'WWPN'列中的字符串值。我想將它作爲參數傳遞給另一個搜索的方法。這與將發送者重新放回列表項目或端口結果一樣簡單?傳遞列表框項目到DoubleClick事件
private void BrowseFlogiDatabase_Click(object sender, RoutedEventArgs e)
{
CollectionWindow cw = new CollectionWindow(this.VirtualFabricList);
GridView grid = new GridView();
GridViewColumn FCPortColumn = new GridViewColumn();
FCPortColumn.Header = "FC Port";
FCPortColumn.Width = Double.NaN;
FCPortColumn.DisplayMemberBinding = new Binding("FCPort");
GridViewColumn WWPNColumn = new GridViewColumn();
WWPNColumn.Header = "WWPN";
WWPNColumn.Width = Double.NaN;
WWPNColumn.DisplayMemberBinding = new Binding("WWPN");
GridViewColumn FCIDColumn = new GridViewColumn();
FCIDColumn.Header = "FCID";
FCIDColumn.Width = Double.NaN;
FCIDColumn.DisplayMemberBinding = new Binding("FCID");
GridViewColumn SwitchNameColumn = new GridViewColumn();
SwitchNameColumn.Header = "SwitchName";
SwitchNameColumn.Width = Double.NaN;
SwitchNameColumn.DisplayMemberBinding = new Binding("SwitchName");
grid.Columns.Add(FCPortColumn);
grid.Columns.Add(WWPNColumn);
grid.Columns.Add(FCIDColumn);
grid.Columns.Add(SwitchNameColumn);
cw.CollectionListView.View = grid;
ObservableCollection<PortResult> flogidatabase = new ObservableCollection<PortResult>();
var cs = this.switchList.Where(c => c.switchName == this.ProcessedSwitchesListView.SelectedItem.ToString());
foreach (KeyValuePair<string, FCPort> portpair in cs.FirstOrDefault().FlogiDatabase)
{
PortResult pr = new PortResult();
pr.WWPN = portpair.Key.ToUpper();
pr.FCPort = portpair.Value.ToString();
pr.FCID = portpair.Value.WWPNList.Where(w => w.WWPNValue == pr.WWPN).Select(t => t.FCIDValue).FirstOrDefault().ToString();
pr.SwitchName = cs.FirstOrDefault().switchName;
flogidatabase.Add(pr);
}
cw.CollectionListView.ItemsSource = flogidatabase;
FlogiAddDoubleClickEventStyle(cw, new MouseButtonEventHandler(FlogiDB_MouseDoubleClick));
cw.Show();
}
private void FlogiDB_MouseDoubleClick(Object sender, EventArgs e)
{
MessageBox.Show("FlogiDatabase DoubleClick");
}
我已經知道我可以將發件人轉換爲System.Windows.Controls.ListViewItem,但我仍然無法弄清楚如何獲取其中的值。 System.Windows.Forms也有一個包含SubItems的ListViewItem。大多數示例都使用它,但我使用的ListViewItem沒有該屬性。 –