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

Vertical Alignment - Top - when columns wrap

1 Answer 683 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sculver
Top achievements
Rank 1
sculver asked on 17 Sep 2009, 08:54 PM
I am trying to generate a grid, where the last column will have data in it that is long and will be forced to wrap.

However, when I do this, the other columns are all aligned vertically in the center.  I have tried almost every property related to alignment in the grid, in the templates, and even outside, and can't find a way to get the alignment to go to the TOP by default for the columns.

Here is a simply slimmed down version of my grid to demonstrate the issue.  I have hard coded the last column to 100 for height, but it actually varies and is usually larger than that.

<UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"  xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"  x:Class="SilverlightApplication2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
  <Grid x:Name="LayoutRoot" VerticalAlignment="Top">
    <telerikGridView:RadGridView>
            <telerikGridView:RadGridView.Columns>
                <telerikGridView:GridViewColumn Header="Edit">
                    <telerikGridView:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Edit" />
                        </DataTemplate>
                    </telerikGridView:GridViewColumn.CellTemplate>
                </telerikGridView:GridViewColumn>
                <telerikGridView:GridViewColumn Header="Date" >
                    <telerikGridView:GridViewColumn.CellEditTemplate>
                        <DataTemplate>
                            <controls:DatePicker VerticalAlignment="Top" />
                        </DataTemplate>
                    </telerikGridView:GridViewColumn.CellEditTemplate>
                    <telerikGridView:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock VerticalAlignment="Top" />
                        </DataTemplate>
                    </telerikGridView:GridViewColumn.CellTemplate>
                </telerikGridView:GridViewColumn>
                <telerikGridView:GridViewColumn Header="Hours">
                    <telerikGridView:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock VerticalAlignment="Top" />
                        </DataTemplate>
                    </telerikGridView:GridViewColumn.CellTemplate>
                </telerikGridView:GridViewColumn>
                <telerikGridView:GridViewColumn Header="Activities">
                    <telerikGridView:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Height="100" />
                        </DataTemplate>
                    </telerikGridView:GridViewColumn.CellTemplate>
                </telerikGridView:GridViewColumn>
            </telerikGridView:RadGridView.Columns>
        </telerikGridView:RadGridView>
  </Grid>
</UserControl>

1 Answer, 1 is accepted

Sort by
0
Kalin Milanov
Telerik team
answered on 23 Sep 2009, 10:12 AM
Hello Sculver,

The theory behind your case is as follows:
Every cell has a ContentPresenter which displays ... well content which follows a certain theme defined template. When you are changing the DataTemplate of the cell you are replacing that theme defined template with your own (TextBlock in your case). Therefore setting a VerticalAlignment to your content (TextBlock) will not affect the ContentPresenter of the cell, just the text position within the presenter. What you need to is change the VerticalAlignment of the ContentPresenter itself (which is Center by default).

What you can do in this case is to define a style for the cell and apply it to the columns by using the CellStyle property. In the style setter you set the VerticalContentAlignment property to Top and you are done.

I believe this should do the trick for your case.
For further reference please review the sample application I have prepared for you.

Best wishes,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
sculver
Top achievements
Rank 1
Answers by
Kalin Milanov
Telerik team
Share this question
or