We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Vertical Alignment of Text in the Rows, when using DataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

119765 Jul 29,2015 06:29 AM UTC Jul 31,2015 10:43 AM UTC WinRT 2
loading
Tags: SfDataGrid
Yatharth Gupta
Asked On July 29, 2015 06:29 AM UTC

I am using a DataGrid that displays about 25-30 rows. I wanted to figure out how do I set the VerticalAlignment (to Middle) for the text in each of these rows. Preferably in C#. 

Thanks\Y


Farjana Parveen Ayubb [Syncfusion]
Replied On July 29, 2015 03:37 PM UTC

Hi Yatharth,

Thank you for contacting Syncfusion support.

We have analyzed your query. By default we have set the VerticalAlignmet as center for all the columns except GridTemplateColumn in SfDataGrid. If you want to set the VerticalAlignment as Center for GridTemplateColumn then you have to set VerticalAlignment in corresponding control which you have loaded into the GridTemplateColumn.CellTemplate.

Please refer the below code snippet and sample in the following location:

Code Snippet:

<syncfusion:GridTemplateColumn MappingName="Expense">

                    <syncfusion:GridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <TextBlock Text="{Binding Expense}" VerticalAlignment="Center"  />

                        </DataTemplate>

                    </syncfusion:GridTemplateColumn.CellTemplate>                </syncfusion:GridTemplateColumn>


Sample Location: Vertical_Alignment


Regards,
Farjana Parveen A

Farjana Parveen Ayubb [Syncfusion]
Replied On July 31, 2015 10:43 AM UTC

Hi Yatharth,

In our pervious solution, you can set the VerticalAlignment as Center for GridTemplateColumn in XAML and you can also define the VerticalAlignment as Center for GridTemplateColumn in code behind, please refer the below code snippet. We also attached the simple sample in the following location:

Code Snippet:

var datatemplate = "<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" +

"<TextBlock Text=\"{Binding Expense}\" VerticalAlignment = \"Center\"/>" +

"</DataTemplate>";

DataTemplate template = (DataTemplate)Windows.UI.Xaml.Markup.XamlReader.Load(datatemplate);
this.SfDataGrid.Columns.Add(new GridTemplateColumn() { CellTemplate = template, MappingName = "Expense"});


Sample Location: Vertical_Alignment


Regards,
Farjana Parveen A

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;