Lost In Code
Lost In Code

Reputation: 504

WPF Bind IsEnabled for an unbound checkbox?

I have a grid where unchecking/checking the box in the header row does the same on every row in the box in this column on all rows. The column is Unbound to the view model, using the implementation taken from here: http://www.devexpress.com/Support/Center/p/E1263.aspx

Here is the markup for column with the check boxes. This creates a box user clicks on mark the row as signed-off:

<dxg:GridColumn FieldName="UnboundCheck" Header="SignOff" UnboundType="Boolean"  Width="85px" Visible="True" >
    <dxg:GridColumn.HeaderTemplate>
        <DataTemplate>
            <dxe:CheckEdit Content="{Binding}"  Checked="CheckEdit_Checked" Unchecked="CheckEdit_Unchecked"/>
        </DataTemplate>
    </dxg:GridColumn.HeaderTemplate>
</dxg:GridColumn>

User also has ability to click on each individual checkbox, but there is a new requirement to check user permission first. I need to set IsEnabled on each row based on another column that indicates if user has permission to check off the box. I tried adding CellTemplate to the GrideColumn, and using binding like this:

    <dxg:GridColumn.CellTemplate>
        <DataTemplate>
             <dxe:CheckEdit Content=" hi" IsEnabled="{Binding CanBeSignedOff,RelativeSource={RelativeSource TemplatedParent},diag:PresentationTraceSources.TraceLevel=High}" />
        </DataTemplate>
    </dxg:GridColumn.CellTemplate>

But the binding is not working, with error message:

System.Windows.Data Error: 40 : BindingExpression path error: 'CanBeSignedOff' property not found on 'object' ''CellEditor' (Name='PART_CellEditor')'. BindingExpression:Path=CanBeSignedOff; DataItem='CellEditor' (Name='PART_CellEditor'); target element is 'CheckEdit' (Name=''); target property is 'IsEnabled' (type 'Boolean')

I also tried:

{Binding CanBeSignedOff,RelativeSource={RelativeSource AncestorType={x:Type dxg:GridRow}}

But got path error of "property not found on 'object' ''GridRow' "

Is it possible to use binding on the cells when the column is unbounded?

Upvotes: 0

Views: 1255

Answers (1)

Fede
Fede

Reputation: 44068

Change

<dxe:CheckEdit Content=" hi" IsEnabled="{Binding CanBeSignedOff,RelativeSource={RelativeSource TemplatedParent},diag:PresentationTraceSources.TraceLevel=High}" /

to

<dxe:CheckEdit Content=" hi" IsEnabled="{Binding DataContext.CanBeSignedOff,RelativeSource={RelativeSource TemplatedParent},diag:PresentationTraceSources.TraceLevel=High}" /

or

<dxe:CheckEdit Content=" hi" IsEnabled="{Binding DataContext.RowData.Row.CanBeSignedOff,RelativeSource={RelativeSource TemplatedParent},diag:PresentationTraceSources.TraceLevel=High}" /

Upvotes: 2

Related Questions