private TreeViewItem FindTreeViewItemUnderTreeViewItemByModelName(TreeViewItem tvi, string modelName) { TreeViewItem treeViewItemRet = null; if (tvi != null) { ICrowdMemberModel model = tvi.DataContext as ICrowdMemberModel; if (model.Name == modelName) { return(tvi); } else if (tvi.Items != null) { for (int i = 0; i < tvi.Items.Count; i++) { TreeViewItem item = tvi.ItemContainerGenerator.ContainerFromItem(tvi.Items[i]) as TreeViewItem; var treeViewItem = FindTreeViewItemUnderTreeViewItemByModelName(item, modelName); if (treeViewItem != null) { treeViewItemRet = treeViewItem; break; } } } } return(treeViewItemRet); }
public static object GetCurrentSelectedCrowdInCrowdCollection(Object tv, out ICrowdMemberModel crowdMember) { CrowdModel containingCrowdModel = null; crowdMember = null; TreeView treeView = tv as TreeView; if (treeView != null && treeView.SelectedItem != null) { if (treeView.SelectedItem is CrowdModel) { containingCrowdModel = treeView.SelectedItem as CrowdModel; } else { DependencyObject dObject = treeView.GetItemFromSelectedObject(treeView.SelectedItem); TreeViewItem tvi = dObject as TreeViewItem; // got the selected treeviewitem crowdMember = tvi.DataContext as ICrowdMemberModel; dObject = VisualTreeHelper.GetParent(tvi); // got the immediate parent tvi = dObject as TreeViewItem; // now get first treeview item parent while (tvi == null) { dObject = VisualTreeHelper.GetParent(dObject); tvi = dObject as TreeViewItem; } containingCrowdModel = tvi.DataContext as CrowdModel; } } return(containingCrowdModel); }
public void Remove(ICrowdMemberModel member) { if (member == null) { return; } this.crowdMemberCollection.Remove(member); member.PropertyChanged -= Member_PropertyChanged; }
private void viewModel_ExpansionUpdateNeeded(object sender, CustomEventArgs <ExpansionUpdateEvent> e) { CrowdModel crowdModel = sender as CrowdModel; DependencyObject dObject = null; ExpansionUpdateEvent updateEvent = e.Value; if (updateEvent == ExpansionUpdateEvent.Filter) { ExpandMatchedNode(sender); } else if (updateEvent == ExpansionUpdateEvent.DragDrop) { if (this.currentDropItemNode != null) { this.currentDropItemNode.IsExpanded = true; } } else { if (this.selectedCrowdRoot != null && crowdModel != null) { TreeViewItem item = treeViewCrowd.ItemContainerGenerator.ContainerFromItem(this.selectedCrowdRoot) as TreeViewItem; dObject = FindTreeViewItemUnderTreeViewItemByModelName(item, crowdModel.Name); if (dObject == null) { dObject = treeViewCrowd.GetItemFromSelectedObject(crowdModel); } } else { dObject = treeViewCrowd.GetItemFromSelectedObject(crowdModel); } TreeViewItem tvi = dObject as TreeViewItem; if (tvi != null) { ICrowdMemberModel model = tvi.DataContext as ICrowdMemberModel; if (tvi.Items != null && tvi.Items.Count > 0) { if (updateEvent != ExpansionUpdateEvent.Delete) { tvi.IsExpanded = true; } else { UpdateExpansions(tvi); } } else { tvi.IsExpanded = false; } } } }
private void viewModel_EditNeeded(object sender, CustomEventArgs <string> e) { ICrowdMemberModel modelToSelect = sender as ICrowdMemberModel; if (sender == null) // need to unselect { DependencyObject dObject = treeViewCrowd.GetItemFromSelectedObject(treeViewCrowd.SelectedItem); TreeViewItem tvi = dObject as TreeViewItem; // got the selected treeviewitem if (tvi != null) { tvi.IsSelected = false; this.selectedCrowdRoot = null; } } else { bool itemFound = false; TextBox txtBox = null; treeViewCrowd.UpdateLayout(); if (this.viewModel.SelectedCrowdModel == null) { var allCharsCrowd = this.viewModel.CrowdCollection[Constants.ALL_CHARACTER_CROWD_NAME]; if (allCharsCrowd != null) { TreeViewItem firstItem = treeViewCrowd.ItemContainerGenerator.ContainerFromItem(allCharsCrowd) as TreeViewItem; if (firstItem != null) { firstItem.IsSelected = true; this.viewModel.SelectedCrowdModel = firstItem.DataContext as CrowdModel; } } } if (sender is CrowdModel) { if (this.viewModel.SelectedCrowdModel == null || this.viewModel.SelectedCrowdModel.Name == Constants.ALL_CHARACTER_CROWD_NAME) // A new crowd has been added to the collection { for (int i = 0; i < treeViewCrowd.Items.Count; i++) { TreeViewItem item = treeViewCrowd.ItemContainerGenerator.ContainerFromItem(treeViewCrowd.Items[i]) as TreeViewItem; if (item != null) { var model = item.DataContext as ICrowdMemberModel; if (model.Name == modelToSelect.Name) { item.IsSelected = true; itemFound = true; txtBox = FindTextBoxInTemplate(item); this.viewModel.SelectedCrowdModel = model as CrowdModel; break; } } } } } if (!itemFound) { DependencyObject dObject = null; if (e != null) // Something sent as event args { if (e.Value == "EditAfterDragDrop" && this.currentDropItemNodeParent != null) { dObject = currentDropItemNodeParent; } } else { if (this.selectedCrowdRoot != null && this.viewModel.SelectedCrowdModel != null) { TreeViewItem item = treeViewCrowd.ItemContainerGenerator.ContainerFromItem(this.selectedCrowdRoot) as TreeViewItem; dObject = FindTreeViewItemUnderTreeViewItemByModelName(item, this.viewModel.SelectedCrowdModel.Name); } else { dObject = treeViewCrowd.GetItemFromSelectedObject(this.viewModel.SelectedCrowdModel); } } TreeViewItem tvi = dObject as TreeViewItem; // got the selected treeviewitem if (tvi != null) { ICrowdMemberModel model = tvi.DataContext as ICrowdMemberModel; if (tvi.Items != null) { tvi.IsExpanded = true; tvi.UpdateLayout(); for (int i = 0; i < tvi.Items.Count; i++) { TreeViewItem item = tvi.ItemContainerGenerator.ContainerFromItem(tvi.Items[i]) as TreeViewItem; if (item != null) { model = item.DataContext as ICrowdMemberModel; if (model.Name == modelToSelect.Name) { item.IsSelected = true; itemFound = true; item.UpdateLayout(); txtBox = FindTextBoxInTemplate(item); if (model is CrowdModel) { this.viewModel.SelectedCrowdModel = model as CrowdModel; this.viewModel.SelectedCrowdParent = tvi.DataContext as CrowdModel; } else { this.viewModel.SelectedCrowdMemberModel = model as CrowdMemberModel; this.viewModel.SelectedCrowdModel = tvi.DataContext as CrowdModel; } if (this.selectedCrowdRoot == null) { this.selectedCrowdRoot = tvi.DataContext as CrowdModel; } break; } } } } } } if (txtBox != null) { this.viewModel.EnterEditModeCommand.Execute(txtBox); } } }
private void UnLoadCharacter(object state) { ICrowdMemberModel model = state as ICrowdMemberModel; //if (model != null && this.EditedCharacter.Name == model.Name) // this.EditedCharacter = null; }
public void Add(ICrowdMemberModel member) { this.crowdMemberCollection.Add(member); this.crowdMemberCollection.Sort(ListSortDirection.Ascending, new CrowdMemberModelComparer()); member.PropertyChanged += Member_PropertyChanged; }