Inheritance: System.Windows.Controls.HeaderedItemsControl
Ejemplo n.º 1
0
 /// <summary>
 /// Recalculates the size of the presenter to match its parent.
 /// </summary>
 /// <param name="sender">Sender</param>
 /// <param name="e">Event args</param>
 private void OnSizeChanged(object sender, SizeChangedEventArgs e)
 {
     if (_presenter != null)
     {
         ExpanderView     parent = _presenter.GetParentByType <ExpanderView>();
         GeneralTransform gt     = parent.TransformToVisual(_presenter);
         Point            childToParentCoordinates = gt.Transform(new Point(0, 0));
         _presenter.Width = parent.RenderSize.Width + childToParentCoordinates.X;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// IsNonExpandableProperty changed handler.
        /// </summary>
        /// <param name="obj">The dependency object.</param>
        /// <param name="e">The event information.</param>
        private static void OnIsNonExpandablePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            ExpanderView source = (ExpanderView)obj;

            if ((bool)e.NewValue)
            {
                if (source.IsExpanded)
                {
                    source.IsExpanded = false;
                }
            }

            source.UpdateVisualState(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// IsExpandedProperty changed handler.
        /// </summary>
        /// <param name="obj">The dependency object.</param>
        /// <param name="e">The event information.</param>
        private static void OnIsExpandedPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            ExpanderView source = (ExpanderView)obj;

            RoutedEventArgs args = new RoutedEventArgs();

            if ((bool)e.NewValue)
            {
                source.OnExpanded(args);
            }
            else
            {
                source.OnCollapsed(args);
            }

            source.UpdateVisualState(true);
        }
        public void InitTreeView()
        {
            if (null == _ds)
                throw new ArgumentNullException("DataSource", "数据源不能为空");

            List<ExpanderSelectorDataSource> list = _ds.GetRoots();

            foreach (var item in list)
            {
                if(_ds.IsLeaf(item.ID))
                {
                    var leaf = new Border
                    {
                        Margin = new Thickness(0, 10, 0, 0),
                        Style = Application.Current.Resources["ExpanderLeafComp"] as Style,
                        Child = new TextBlock()
                        {
                            Text = item.Name,
                            Style = Application.Current.Resources["ExpanderViewTextBlock"] as Style
                        },
                    };

                    leaf.Tag = item;
                    leaf.Tap += leaf_Tap;
                    EVStack.Children.Add(leaf);
                }
                else
                {
                    ExpanderView view = new ExpanderView
                    {
                        Style = Application.Current.Resources["ExpanderViewStyleForSelector"] as Style,
                        Margin = new Thickness(0, 10, 0, 0),

                        Expander = new Grid
                        {
                            Width = Application.Current.Host.Content.ActualWidth,
                            Background = new SolidColorBrush(Color.FromArgb(255, 186, 122, 53)),
                            Children = { 
                            new TextBlock
                            {
                                Text = item.Name,
                                Style = Application.Current.Resources["ExpanderViewTextBlock"] as Style
                            },
                            new Image
                            {
                                Style = Application.Current.Resources["ExpanerViewSeeMoreIcon"] as Style,
                                Margin = new Thickness(indentSeeMoreIcon, 0, 0, 0),
                            }
                        }
                        }
                    };

                    InitChildViewRecursion(item.ID, ref view, 1);
                    EVStack.Children.Add(view);
                }
            }
        }
        private void InitChildViewRecursion(String Id, ref ExpanderView ev, int level)
        {
            List<ExpanderSelectorDataSource> list = _ds.GetChildNodeById(Id);

            if (null != list && list.Count() != 0)
            {
                foreach (var item in list)
                {
                    //根节点
                    if (_ds.IsLeaf(item.ID))
                    {
                        var leaf = new Border
                        {
                            Margin = new Thickness(indentChildExpander, 10, 0, 0),
                            Style = Application.Current.Resources["ExpanderLeafComp"] as Style,
                            Child = new TextBlock()
                            {
                                Text = item.Name,
                                Style = Application.Current.Resources["ExpanderViewTextBlock"] as Style
                            },
                        };

                        leaf.Tag = item;
                        leaf.Tap += leaf_Tap;
                        ev.Items.Add(leaf);
                    }
                    else //非根节点,继续搜索
                    {
                        ExpanderView view = new ExpanderView
                        {
                            Style = Application.Current.Resources["ExpanderViewStyleForSelector"] as Style,
                            Margin = new Thickness(indentChildExpander, 10, 0, 0),

                            Expander = new Border
                            {
                                Background = new SolidColorBrush(Color.FromArgb(255, 186, 122, 53)),

                                Child = new Grid
                                {
                                    Width = Application.Current.Host.Content.ActualWidth,
                                    Background = new SolidColorBrush(Color.FromArgb(255, 186, 122, 53)),
                                    Children = {
                                        new TextBlock
                                        {
                                            Text = item.Name,
                                            Style = Application.Current.Resources["ExpanderViewTextBlock"] as Style
                                        }, 
                                        new Image
                                        {
                                            Style = Application.Current.Resources["ExpanerViewSeeMoreIcon"] as Style,
                                            Margin = new Thickness(indentSeeMoreIcon - indentChildExpander * level, 0, 0, 0)
                                        } 
                                    }
                                }
                            },

                        };

                        view.Tap += view_Tap;

                        InitChildViewRecursion(item.ID, ref view, level + 1);
                        ev.Items.Add(view);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void CreateItem(ExpanderView list, String groupName)
        {
            var transform = list.TransformToVisual(Application.Current.RootVisual);
            var pointOffset = transform.Transform(new Point(0, 0));
            double verticalOffset = pointOffset.Y - 50;

            var createItem = new CreateItemControl()
            {
                GroupName = groupName
            };
            SetPopupedControlEvent(createItem);

            createItem.Closed += delegate(object sender, PopupEventArgs e)
            {
                list.IsExpanded = true;
                if (verticalOffset > 0)
                {
                    var storyboard2 = AnimationUtils.GetStoryboard();
                    AnimationUtils.SetHeightAnimation(storyboard2, VacancyStackPanel as FrameworkElement, 0, 0.3);
                    storyboard2.Begin();
                }

                if (e.Done)//Expand the new item
                {
                    FrameworkElement item = list.Items[0] as FrameworkElement;
                    if (item != null)
                    {
                        StackPanel panel = item.FindName("ItemPanel") as StackPanel;
                        if (panel != null)
                        {
                            if (mCurrentItemPanel != null)
                            {
                                HideItemDetails(mCurrentItemPanel);
                            }
                            ShowItemDetails(panel);
                            mCurrentItemPanel = panel;
                        }
                    }
                }

            };

            if (verticalOffset == 0)
            {
                PopupWindow.ShowWindow(createItem);
            }
            else
            {
                var storyboard = AnimationUtils.GetStoryboard();
                if (verticalOffset > 0)
                {
                    AnimationUtils.SetHeightAnimation(storyboard, VacancyStackPanel as FrameworkElement, verticalOffset + 1000, 0.3);
                }
                AnimationUtils.SetAnyAnimation(storyboard, this as FrameworkElement, ScrowViewerVerticalOffsetProperty,
                                               MainScrollViewer.VerticalOffset, MainScrollViewer.VerticalOffset + verticalOffset, 0.3);

                storyboard.Completed += delegate(object sender, EventArgs e)
                {
                    PopupWindow.ShowWindow(createItem);
                };
                storyboard.Begin();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// NonExpandableHeaderTemplate changed handler.
        /// </summary>
        /// <param name="obj">The dependency object.</param>
        /// <param name="e">The event information.</param>
        private static void OnNonExpandableHeaderTemplatePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            ExpanderView source = (ExpanderView)obj;

            source.OnNonExpandableHeaderTemplateChanged((DataTemplate)e.OldValue, (DataTemplate)e.NewValue);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// ExpanderProperty changed handler.
        /// </summary>
        /// <param name="obj">The dependency object.</param>
        /// <param name="e">The event information.</param>
        private static void OnExpanderPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            ExpanderView source = (ExpanderView)obj;

            source.OnExpanderChanged(e.OldValue, e.NewValue);
        }