This is a migrated thread and some comments may be shown as answers.

Binding cell with RelativeSource FindAncestor

1 Answer 465 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alvaro
Top achievements
Rank 1
Alvaro asked on 21 Jan 2011, 11:27 AM

Good day,

I am using RadGridView control using 2009 Q2 version of Telerik. And i have the following problem.

I am using bindings for having some control on some behavior into the Grid. My idea is, binding the column to a property, set unable and disable the checkbox we have in the column. For that i use RelativeSource FindAncestor

<telerik:GridViewDataColumn UniqueName="List" IsFilterable="False" Width="100">
    <telerik:GridViewColumn.HeaderCellStyle>
        <Style TargetType="telerik:GridViewHeaderCell">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:GridViewHeaderCell">
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="Edit" HorizontalAlignment="Center"></TextBlock>
                            <CheckBox x:Name="AllEdited" HorizontalAlignment="Center" VerticalAlignment="Center" Click="AllEdited_Click" Validation.ErrorTemplate="{x:Null}" IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=DataContext.EditMode}"></CheckBox>
                        </StackPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </telerik:GridViewColumn.HeaderCellStyle>
    <telerik:GridViewColumn.CellStyle>
        <Style TargetType="telerikGridView:GridViewCell">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerikGridView:GridViewCell">
                        <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding CuestionarioVisible}" Validation.ErrorTemplate="{x:Null}" IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=DataContext.EditMode}"></CheckBox>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </telerik:GridViewColumn.CellStyle>
</telerik:GridViewDataColumn>

As you can see in the code, I have binding on "IsEnabled" property for allowing or not to check on the checkboxes which was edited or not.
The binding works great in the header but, it ignores in the cell!

Any ideas? Why is that happening? Any solution for making the cells work in the same way as the header?

Thanks in advance.

Regards,
Alvaro

1 Answer, 1 is accepted

Sort by
0
Alvaro
Top achievements
Rank 1
answered on 24 Jan 2011, 04:04 PM
Any idea over here?
Tags
GridView
Asked by
Alvaro
Top achievements
Rank 1
Answers by
Alvaro
Top achievements
Rank 1
Share this question
or