Question

I have a reference to a GridViewColumn in my xaml code as RuntimeColumn but I am not able to disable it or set it to readonly programmatically. I will need to do this at runtime without databinding.

I tried:

this.RuntimeColumn.IsEnabled = false;
this.RuntimeColumn.ReadOnly = false;

Any ideas?

Was it helpful?

Solution

You will have to set an EventSetter with Loaded Event, and in your code behind put the following

private void GridViewColumnHeader_Loaded(object sender, RoutedEventArgs e)
    {            
        GridViewColumnHeader columnHeader = sender as GridViewColumnHeader;
        Border HeaderBorder = columnHeader.Template.FindName("HeaderBorder", columnHeader) as Border;
        if (HeaderBorder != null)
        {
            HeaderBorder.Background = HeaderBorder.Background;
        }
        Border HeaderHoverBorder = columnHeader.Template.FindName("HeaderHoverBorder", columnHeader) as Border;
        if (HeaderHoverBorder != null)
        {
            HeaderHoverBorder.BorderBrush = HeaderHoverBorder.BorderBrush;
        }
        Rectangle UpperHighlight = columnHeader.Template.FindName("UpperHighlight", columnHeader) as Rectangle;
        if (UpperHighlight != null)
        {
            UpperHighlight.Visibility = UpperHighlight.Visibility;
        }
        Thumb PART_HeaderGripper = columnHeader.Template.FindName("PART_HeaderGripper", columnHeader) as Thumb;            
        if (PART_HeaderGripper != null)
        {
            PART_HeaderGripper.Background = PART_HeaderGripper.Background;
            PART_HeaderGripper.Cursor = System.Windows.Input.Cursors.Arrow; // override the size curser
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top