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

Wrap the text in all the columns header using style xaml

3 Answers 382 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Will
Top achievements
Rank 1
Will asked on 03 Sep 2015, 04:45 PM

I don't know how to wrap columns header using just a style. I cannot use code behind because we don't have code behind. We use MVVM and CaliburnMicro so we don't have code behind the view. So I was trying to apply style to the grid and wrap all the headers every time I add grid to the form but I cannot accomplish this task. I don't want to do wrap to every column every time I add the grid. So my Idea was but it doesn't work. Please advice.

<Style TargetType="telerik:GridViewDataColumn" >
        <Setter Property="Header">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock TextWrapping="Wrap" Text="{Binding}"></TextBlock>
                </DataTemplate>
            </Setter.Value>
      </Setter>
 </Style>

 Thank you,

Grazyna

 

 

3 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 04 Sep 2015, 07:51 AM
Hello Grazyna,

You can easily achieve the desired behavior by using the following style:
<telerik:RadGridView.Resources>
                <Style TargetType="telerik:GridViewHeaderCell">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <TextBlock Text="long long logn text" TextWrapping="Wrap" />
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </telerik:RadGridView.Resources>


Regards,
Yoan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jon
Top achievements
Rank 1
answered on 13 Feb 2020, 12:08 AM

Yoan,

Nice, so now all headers will say "long long logn text". Frankly, no sane person would think that is the desired behavior.

 

-Jon

0
Yoan
Telerik team
answered on 17 Feb 2020, 02:30 PM

Hello Jon,

Indeed, you are right. The example was not complete. It had to show that if you are using a style targeting the GridViewHeaderCell element (instead of GridViewDataColumn), then the binding will work. However, I missed this part. Here is a complete style that should be used:

<telerik:RadGridView ItemsSource="{Binding}">
            <telerik:RadGridView.Resources>
                <Style TargetType="telerik:GridViewHeaderCell">
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <TextBlock Text="{Binding}" TextWrapping="Wrap" />
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </telerik:RadGridView.Resources>
        </telerik:RadGridView>

In this way, the TextBlock's Text property will be bound to the "Header" property of the GridViewHeaderCell element (which is the DataContext of the header cell).

Also, I have attached a sample project where this can be observed.

Regards,
Yoan
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Will
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Jon
Top achievements
Rank 1
Share this question
or