//event handler for the GridViewColumnHeader click
        private static void OnColumnHeaderClicked(object sender, RoutedEventArgs e)
        {
            ListView view = sender as ListView;

            if (view == null)
            {
                return;
            }

            GridViewSortHandler handler = view.GetValue(GridViewSortHandlerProperty) as GridViewSortHandler;

            if (handler == null)
            {
                return;
            }

            //set the parent control of the handler
            handler.parentControl = view;
            handler.comparer      = view.GetValue(CustomComparerProperty) as GridViewCustomComparer;

            GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader;

            // ensure that we clicked on the column header and not the padding that's added to fill the space.
            if (headerClicked != null && headerClicked.Role != GridViewColumnHeaderRole.Padding)
            {
                // attempt to cast to the sortableGridViewColumn object.
                SortableGridViewColumn sortableGridViewColumn = headerClicked.Column as SortableGridViewColumn;
                if (sortableGridViewColumn.CanSort)
                {
                    handler.ApplySort(sortableGridViewColumn);
                }
            }
        }