/// <summary> /// 處理滑鼠左鍵連點在可選/已選項 /// </summary> public void AddClickedItem(object obj) { System.Windows.Controls.TextBlock itemTextBlock = obj as System.Windows.Controls.TextBlock; if (itemTextBlock == null) { return; } ItemViewModel itemViewModel; foreach (KeyValuePair <int, string> item in AvailableItemList) { if (item.ToString() == itemTextBlock.Text) { itemViewModel = new ItemViewModel(); itemViewModel.Item = item; itemViewModel.IsSelected = false; if (SelectedItemsInListBox.Count() > 0) { var a = SelectedItemsInListBox.Select(x => x.Item == itemViewModel.Item); if (!a.Contains(true)) { SelectedItemsInListBox.Add(itemViewModel); return; } } else { AvailableItemsInListBox.Add(itemViewModel); } } } }
private void AddSelectedItem(object obj) { foreach (var item in ItemToAddList) { if (!SelectedItemsInListBox.Contains(item)) { SelectedItemsInListBox.Add(item); } } }