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

Gridview template column with top aligned button

1 Answer 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Kjell asked on 08 Sep 2010, 07:54 PM
Hi, I have a gridview with several template columns which contains buttons.  I need those buttons to be top aligned but for some reason they keep being forced to be vertically centered.

Here is an example of one of the columns:

<telerik:GridViewColumn>
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton Content="Delete" Command="telerik:RadGridViewCommands.Delete" CommandParameter="{Binding}" 
                                                   VerticalAlignment="Top" HorizontalAlignment="Center"  Height="20"  Margin="0,0,0,0" />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>

It looks fine when the row is only 1 line tall but when the row grows it becomes obvious that the button is middle aligned instead of top aligned.  I must be missing something really obvious here but it's been driving me crazy.

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 09 Sep 2010, 07:50 AM
Hello Kjell,

The most probable reason for not respecting the VerticalAlignment setting may be that the content of the cell may have some predefined size that does not allow you to apply a new value. So, what you can do is to create a new style in the Resource of the grid targeting the GridViewCell and set it for the CellStyle of that certain column. 
For example:

<UserControl.Resources>       
    <Style x:Key="MyCellStyle" TargetType="telerik:GridViewCell">
        <Setter Property="VerticalAlignment" Value="Top" />
    </Style>
</UserControl.Resources>

<telerik:GridViewColumn CellStyle="{StaticResource MyCellStyle}" >
    <telerik:GridViewColumn.CellTemplate>
        <DataTemplate>
            <telerik:RadButton Content="Delete" 
                         Command="telerik:RadGridViewCommands.Delete"                                      CommandParameter="{Binding}" 
                                  HorizontalAlignment="Center"   />
        </DataTemplate>
    </telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>


 
Sincerely yours,
Maya
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Kjell
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or