使DataGrid的第一行ReadOnly [英] Make first row of DataGrid ReadOnly

查看:111
本文介绍了使DataGrid的第一行ReadOnly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DataGrid在WPF应用程序中显示用户权限。

I'm using a DataGrid to display user permissions in my WPF-application.

DataGrid的第一行将始终包含项目的所有者,将显示权限。

The first row of the DataGrid will always contain the owner of the project for which the permissions are displayed.

创建项目时,该所有者将被设置,不能直接从DataGrid更改。

This owner is set when the project is created and can not be changed directly from the DataGrid.

我的问题是。

如何使第一行ReadOnly,或者可以给它一个特定的样式,以便背景可以改变? >

How can I make the first row ReadOnly, and maybe give it a specific style so the background can be changed?

推荐答案

您将需要一个触发器,唯一的问题是在wpf datagrid上获取行索引是相当可怕的,所以我倾向做这样的事情:

You will need a trigger for this, the only problem is that getting a row index on the wpf datagrid is pretty awful, so i tend to do something like this:

    <DataGrid.RowStyle>
            <Style TargetType="DataGridRow">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=IsOwner}" Value="true">
                        <Setter Property="IsEnabled" Value="False"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </DataGrid.RowStyle>

在对象上有一个属性值,我知道该特定行将是唯一的。所以如果有一个唯一的ID或者所有者一直拥有的东西,你可以绑定到它。

where there's a property value on the object i know will be unique to that particular row. So if there's a unique ID or something that the owner always has, you can bind to that.

setter属性是'IsEnabled',因为datagridrow不包含属性只读,但这将阻止用户修改行。

The setter property is 'IsEnabled' as datagridrow doesn't contain a property for readonly, but this will stop a user modifying the row.

这篇关于使DataGrid的第一行ReadOnly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆