public static int FindAndInsert(Item item) { //检查tagName bool IsAdded = false; if (!string.IsNullOrEmpty(item.TagName)) { foreach (object obj in WindowMain.Recent.Children) { //查找子元素 if (obj is ExpanderEx) { //获取到expander ExpanderEx exTmp = (ExpanderEx)obj; exTmp.IsExpanded = true; //若标签名相同 if (exTmp.tagName == item.TagName) { System.Windows.Controls.WrapPanel wpTmp = (System.Windows.Controls.WrapPanel)exTmp.Content; wpTmp.Children.Add(item); IsAdded = true; } } } //如果未找到相同标签名的分组 if (!IsAdded) { ExpanderEx ex = new ExpanderEx(item.TagName); ex.tagName = item.TagName; ex.IsExpanded = true; System.Windows.Controls.WrapPanel wp = new System.Windows.Controls.WrapPanel(); wp.Children.Add(item); ex.Content = wp; WindowMain.Recent.Children.Add(ex); } } else { WindowMain.Recent.Children.Add(item); } return(0); }
private static void SelectInsert(Item item) { //检查tagName bool IsAdded = false; foreach (object obj in WindowMain.Recent.Children) { //查找子元素 if (obj is ExpanderEx) { //获取到expander ExpanderEx exTmp = (ExpanderEx)obj; exTmp.IsExpanded = true; //若标签名相同 if (exTmp.tagName == item.refItemData.TagName) { System.Windows.Controls.WrapPanel wpTmp = (System.Windows.Controls.WrapPanel)exTmp.Content; wpTmp.Children.Add(item); IsAdded = true; } } } //如果未找到相同标签名的分组 if (!IsAdded) { ExpanderEx ex = new ExpanderEx(item.refItemData.TagName); ex.Style = Application.Current.FindResource("ExpanderExStyle") as Style; System.Windows.Controls.WrapPanel wp = new System.Windows.Controls.WrapPanel(); wp.Children.Add(item); ex.Content = wp; WindowMain.Recent.Children.Add(ex); } }