Back to Devexpress

BaseColumn.IsReadOnlyBinding Property

wpf-devexpress-dot-xpf-dot-grid-dot-basecolumn-acb9404f.md

latest5.0 KB
Original Source

BaseColumn.IsReadOnlyBinding Property

Gets or sets the binding that determines a cell’s read-only state.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
[DefaultValue(null)]
public BindingBase IsReadOnlyBinding { get; set; }
vb
<DefaultValue(Nothing)>
Public Property IsReadOnlyBinding As BindingBase

Property Value

TypeDefaultDescription
BindingBasenull

The binding that associates the read-only state of cells with a property in a data source.

|

Remarks

The code sample below sets cells in the Progress column as read-only if a task has subtasks:

View Example: Read-only and Enabled State Binding

xaml
<dxg:TreeListControl x:Name="treeList"
                     ItemsSource="{Binding Path=EditableDataSource, Source={StaticResource employeeTasks}}">
    <dxg:TreeListControl.Columns>
        <dxg:TreeListColumn FieldName="Name" Header="Task"/>
        <dxg:TreeListColumn FieldName="Employee" Header="Assignee"/>

        <dxg:TreeListColumn FieldName="Status" Header="Progress" 
                            IsReadOnlyBinding="{Binding HasSubtasks}"/>

        <dxg:TreeListColumn FieldName="StartDate"/>
        <dxg:TreeListColumn FieldName="DueDate"/>
    </dxg:TreeListControl.Columns>
    <dxg:TreeListControl.View>
        <dxg:TreeListView x:Name="view" KeyFieldName="ID" ParentFieldName="ParentID"/>
    </dxg:TreeListControl.View>
</dxg:TreeListControl>
csharp
public class EmployeeTask: INotifyPropertyChanged {
    public int ID { get; set; }
    public int ParentID { get; set; }
    public string Name { get; set; }
    public string Employee { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime DueDate { get; set; }  
    public int Status { get; set; }        
    public bool HasSubtasks { get; }

    // ...
}
vb
Public Class EmployeeTask Inherits INotifyPropertyChanged

    Public Property ID As Integer
    Public Property ParentID As Integer
    Public Property Name As String
    Public Property Employee As String
    Public Property StartDate As DateTime
    Public Property DueDate As DateTime
    Public Property Status As Integer

    Public ReadOnly Property IsRoot As Boolean
        Get
            Return ParentID = 0
        End Get
    End Property
End Class

Customize Appearance Settings of Read-only Cells

To change the appearance settings of read-only cells, use the ColumnBase.CellStyle property with a trigger. Use the LightweightCellEditor as the style’s target type.

xaml
<dxg:TreeListColumn.CellStyle>
    <Style TargetType="dxg:LightweightCellEditor">
        <Style.Triggers>
            <Trigger Property="ReadOnly" Value="True">
                <Setter Property="Background" Value="LightGray" />                               
            </Trigger>
        </Style.Triggers>
    </Style>
</dxg:TreeListColumn.CellStyle>

For more information, refer to Disable Editing.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the IsReadOnlyBinding property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-grid-read-only-and-enabled-binding/CS/MainWindow.xaml#L29

xml
</dxg:TreeListColumn>
<dxg:TreeListColumn FieldName="Status" Header="Progress" FixedWidth="True" Width="100" IsReadOnlyBinding="{Binding HasSubtasks}">
    <dxg:TreeListColumn.CellDisplayTemplate>

See Also

BaseColumn Class

BaseColumn Members

DevExpress.Xpf.Grid Namespace