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. Image for the cookie policy date

Vertical Alignment of Text in the Rows, when using DataGrid

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


2 Replies

FP Farjana Parveen Ayubb Syncfusion Team 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


FP Farjana Parveen Ayubb Syncfusion Team 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

Loader.
Up arrow icon