Пример #1
0
        static void Extend_Click(object sender, RoutedEventArgs e)
        {
            var gridViewColumnHeader = e.OriginalSource as GridViewColumnHeader;

            if (GetParent(gridViewColumnHeader) == null)
            {
                SetParent(gridViewColumnHeader, gridViewColumnHeader.FindParent <GridView>());
            }

            var parent = GetParent(gridViewColumnHeader);

            if (gridViewColumnHeader?.Column != null)
            {
                var direction = ListSortDirection.Ascending;
                if (gridViewColumnHeader.Role != GridViewColumnHeaderRole.Padding)
                {
                    if (gridViewColumnHeader != GridViewExtensions.GetLastClicked(parent))
                    {
                        direction = ListSortDirection.Ascending;
                    }
                    else
                    {
                        direction
                            = GetLastDirection(gridViewColumnHeader) == ListSortDirection.Ascending
                        ? ListSortDirection.Descending
                        : ListSortDirection.Ascending;
                    }
                }

                string header = gridViewColumnHeader.Column.Header as string;

                var listView = gridViewColumnHeader.FindParent <ListView>();
                if (listView != null)
                {
                    ItemsControlExtensions.SetSortDirection(listView, direction);
                    ItemsControlExtensions.SetSortName(listView, header);
                }

                SetSortDirection(gridViewColumnHeader, direction);

                // Remove arrow from previously sorted header
                if (GridViewExtensions.GetLastClicked(parent) != null && GridViewExtensions.GetLastClicked(parent) != gridViewColumnHeader)
                {
                    SetSortDirection(GridViewExtensions.GetLastClicked(parent), null);
                }

                GridViewExtensions.SetLastClicked(parent, gridViewColumnHeader);
                SetLastDirection(gridViewColumnHeader, direction);
            }
        }
Пример #2
0
        /// <summary>
        /// Collapses siblings of <param name="Item"/>.
        /// </summary>
        public static void CollapseSiblings(this TreeViewItem Item)
        {
            var Parent = Item.GetParent().As <FrameworkElement>();

            while (!Parent.Is <TreeViewItem>())
            {
                if (Parent == null || Parent.Is <TreeView>())
                {
                    break;
                }
                Parent = Parent.GetParent().As <FrameworkElement>();
            }
            ItemsControlExtensions.CollapseSiblings(Parent as ItemsControl, Item);
        }
Пример #3
0
        static void RegisterSelectNoneOnEmptySpaceClick(object sender, MouseButtonEventArgs e)
        {
            var ItemsControl = sender as ItemsControl;

            if (ItemsControlExtensions.GetSelectNoneOnEmptySpaceClick(ItemsControl) && e.LeftButton == MouseButtonState.Pressed)
            {
                if ((ItemsControl is TreeView && !e.OriginalSource.Is <TreeViewItem>()) ||
                    (ItemsControl is DataGrid && !e.OriginalSource.Is <DataGridRow>()) ||
                    (ItemsControl is ListBox && !e.OriginalSource.Is <ListBoxItem>()))
                {
                    ItemsControl.TryClearSelection();
                }
            }
        }