如何使 GridViewColumn 只读/禁用?

发布于 2024-10-22 08:08:30 字数 252 浏览 1 评论 0原文

我在 xaml 代码中将 GridViewColumn 引用为 RuntimeColumn,但我无法以编程方式禁用它或将其设置为只读。我需要在运行时执行此操作,而无需数据绑定。

我尝试过:

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

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-10-29 08:08:30

您必须使用 Loaded Event 设置 EventSetter,并在后面的代码中添加以下内容

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

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
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文