How to retrieve TextBlock from DataGridColumnHeader HeaderStyle in Silverlight

Posted by Xin on Stack Overflow See other posts from Stack Overflow or by Xin
Published on 2010-02-17T23:44:01Z Indexed on 2010/04/01 7:23 UTC
Read the original article Hit count: 723

As in Silverlight I can't bind directly to a DataGridColumn's property, in order to dynamically change the text of the column header, I have to write the following code using HeaderStyle.

                            <data:DataGridTextColumn.HeaderStyle>
                                <Style TargetType="dataprimitives:DataGridColumnHeader">
                                    <Setter Property="ContentTemplate">
                                        <Setter.Value>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding Resource.ClientName, Mode=OneWay}"/>
                                            </DataTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </data:DataGridTextColumn.HeaderStyle>
                        </data:DataGridTextColumn>

My problem is that now I need to get the Name of the TextBlock from grid.Columns[index]. Is there any way I can do this? I tired to use VisualTreeHelper but since DataGridColumn is not a FrameworkElement it will throw me an error...

Any help would be greatly appreciated!

Xin

© Stack Overflow or respective owner

Related posts about datagridcolumn

Related posts about silverlight-3.0