Column Header template on dynamic colums

4 posts, 0 answers
  1. Mark
    Mark avatar
    61 posts
    Member since:
    Dec 2010

    Posted 30 Jan 2012 Link to this post

    I am using your data table construct to populate a grid with dynamic structured data.

    Data structure snaffled from:
    http://blogs.telerik.com/vladimirenchev/posts/09-04-23/lightweight_datatable_for_your_silverlight_applications.aspx

    I now need to wrap the text in the column header. I have the following in the code behind to remove the xml space.
    private void GridLoaded(Code.AppMessages.ListCompleteMessage.enMessage eMessage)
    {
        if (eMessage == Code.AppMessages.ListCompleteMessage.enMessage.GenericTable)
        {
            foreach (GridViewColumn oCol in RGV1.Columns)
            {
                oCol.Header = oCol.Header.ToString().Replace("_x0020_", " ");
                oCol.MaxWidth = 200;
                oCol.TextWrapping = TextWrapping.Wrap;
            }
        }
    }

    I have no preference as to using a xaml template or code behind. I just can't work out the template structure or get at the text wrapping from the code. This is the xaml.
    <telerik:RadGridView x:Name="RGV1" RowIndicatorVisibility="Collapsed" IsReadOnly="True"
                                CanUserFreezeColumns="False" ShowColumnFooters="True" ShowGroupFooters="True" CanUserResizeColumns="False"
                                ItemsSource="{Binding ReportTable,Mode=OneWay}" />

  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 31 Jan 2012 Link to this post

    Hi Mark ,

    Here is a RadGridView with a column with text wrapping in the header.
    <telerik:RadGridView x:Name="RadGridView1" >
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn >
                        <telerik:GridViewColumn.Header>
                            <TextBlock Text="Lorem Ipsum dolor Sin Amet" TextWrapping="Wrap" />
                        </telerik:GridViewColumn.Header>
                    </telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>


    Kind regards,
    Pavel Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Mark
    Mark avatar
    61 posts
    Member since:
    Dec 2010

    Posted 31 Jan 2012 Link to this post

    Pavel you seemed to have missed the critical point that the columns are DYNAMIC therefore your example is not valid. I have to either apply a style to the column header from the code behind or use a template for the header row applied to the RadGridView, NOT the individual columns.
  4. Mark
    Mark avatar
    61 posts
    Member since:
    Dec 2010

    Posted 13 Feb 2012 Link to this post

    Pavlov
    Having had another go at this issue I have managed to bind the header text to the Column.UniqueName using a control template but I cannot get the textwrapping to work.

    <!--This style is not working!-->
        <Style x:Key="TelerikHeaderCellStyle" TargetType="telerik:GridViewHeaderCell">     
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:GridViewHeaderCell">
                        <TextBlock Text="{Binding Column.UniqueName}" TextWrapping="Wrap" Height="Auto" TextAlignment="Left"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>      
            <Setter Property="Height" Value="Auto" />
        </Style>

Back to Top