public void RemoveItem(CalculationInfoBase item) { if (item != null) { // Сами попытаемся найти выбранный элемент. foreach (object obj in m_CalculatedMembers_Node.Items) { TreeNode <CalculationInfoBase> x = obj as TreeNode <CalculationInfoBase>; if (x != null && x.Info == item) { m_CalculatedMembers_Node.Items.Remove(obj); return; } } foreach (object obj in m_NamedSets_Node.Items) { TreeNode <CalculationInfoBase> x = obj as TreeNode <CalculationInfoBase>; if (x != null && x.Info == item) { m_NamedSets_Node.Items.Remove(obj); return; } } } }
public Calculated_AreaItemWrapper(CalculationInfoBase info) { if (info == null) throw new ArgumentNullException("info"); Caption = info.Name; Name = info.Name; }
void m_Tree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { TreeNode <CalculationInfoBase> node_old = e.OldValue as TreeNode <CalculationInfoBase>; CalculationInfoBase descr_old = null; if (node_old != null) { descr_old = node_old.Info; } TreeNode <CalculationInfoBase> node_new = e.NewValue as TreeNode <CalculationInfoBase>; CalculationInfoBase descr_new = null; if (node_new != null) { descr_new = node_new.Info; } //else //{ // // Иногда по неясным причинам в e.NewValue приходит {object} хотя при установке IsSelected = true узел был корректный. Поэтому в случае если узел определить не удалось, считаем что выбран нулевой узел // if (m_CalculatedMembers_Node.Items.Count > 0) // { // TreeNode<CalculationInfoBase> node0 = m_CalculatedMembers_Node.Items[0] as TreeNode<CalculationInfoBase>; // if (node0 != null) // { // descr_new = node0.Info; // } // } // if(descr_new == null && m_NamedSets_Node.Items.Count > 0) // { // TreeNode<CalculationInfoBase> node0 = m_NamedSets_Node.Items[0] as TreeNode<CalculationInfoBase>; // if (node0 != null) // { // descr_new = node0.Info; // } // } //} EventHandler <SelectionChangedEventArgs <CalculationInfoBase> > handler = SelectionChanged; if (handler != null) { handler(this, new SelectionChangedEventArgs <CalculationInfoBase>(descr_old, descr_new)); } }
public void Initialize(Dictionary<String, CalculationInfoBase> members, Dictionary<String, CalculationInfoBase> sets, CalculationInfoBase toSelect) { ClearTree(); // Default selected node TreeNode<CalculationInfoBase> selected = null; if (members != null) { foreach (CalculationInfoBase info in members.Values) { TreeNode<CalculationInfoBase> node = new TreeNode<CalculationInfoBase>(info.Name, UriResources.Images.CustomMeasure16, info); if(selected == null || info == toSelect) selected = node; m_CalculatedMembers_Node.Items.Add(node); } } if (sets != null) { foreach (CalculationInfoBase info in sets.Values) { TreeNode<CalculationInfoBase> node = new TreeNode<CalculationInfoBase>(info.Name, UriResources.Images.CustomNamedSet16, info); if (selected == null || info == toSelect) selected = node; m_NamedSets_Node.Items.Add(node); } } // Делаем выбранным узел (тот который указан, либо первый из имеющихся) if (selected != null) { // Через событие делаем узел выбранным (иначе на нем фокус не ставится) selected.Loaded += new RoutedEventHandler(node_Loaded); } }
public void RemoveItem(CalculationInfoBase item) { if (item != null) { // Сами попытаемся найти выбранный элемент. foreach (object obj in m_CalculatedMembers_Node.Items) { TreeNode<CalculationInfoBase> x = obj as TreeNode<CalculationInfoBase>; if (x != null && x.Info == item) { m_CalculatedMembers_Node.Items.Remove(obj); return; } } foreach (object obj in m_NamedSets_Node.Items) { TreeNode<CalculationInfoBase> x = obj as TreeNode<CalculationInfoBase>; if (x != null && x.Info == item) { m_NamedSets_Node.Items.Remove(obj); return; } } } }
public void Initialize(Dictionary <String, CalculationInfoBase> members, Dictionary <String, CalculationInfoBase> sets, CalculationInfoBase toSelect) { ClearTree(); // Default selected node TreeNode <CalculationInfoBase> selected = null; if (members != null) { foreach (CalculationInfoBase info in members.Values) { TreeNode <CalculationInfoBase> node = new TreeNode <CalculationInfoBase>(info.Name, UriResources.Images.CustomMeasure16, info); if (selected == null || info == toSelect) { selected = node; } m_CalculatedMembers_Node.Items.Add(node); } } if (sets != null) { foreach (CalculationInfoBase info in sets.Values) { TreeNode <CalculationInfoBase> node = new TreeNode <CalculationInfoBase>(info.Name, UriResources.Images.CustomNamedSet16, info); if (selected == null || info == toSelect) { selected = node; } m_NamedSets_Node.Items.Add(node); } } // Делаем выбранным узел (тот который указан, либо первый из имеющихся) if (selected != null) { // Через событие делаем узел выбранным (иначе на нем фокус не ставится) selected.Loaded += new RoutedEventHandler(node_Loaded); } }