开发者

How to make a GridViewColumn readonly/disabled?

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 programmatica开发者_运维知识库lly. I will need to do this at runtime without databinding.

I tried:

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

Any ideas?


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
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜