Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
370
How to center xamdatagrid header label?
posted

I am having problem centering the header label of xamdatagrid. Here is my xaml and code beind code.

Notice that the 'First Name' and 'Last Name' are always left indented despite the <Setter Property="HorizontalContentAlignment" Value="Center" />.

 

<Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation

xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml

xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="XamDataGridDemo.MainWindow" Title="MainWindow" Height="350" Width="525">

<Window.Resources>

<Style x:Key="Epro36HeaderFont" TargetType="{x:Type igDP:LabelPresenter}">

<Setter Property="FontWeight" Value="Bold"/>

<Setter Property="Background" Value="LightGray" />

<

 

 

Setter Property="HorizontalContentAlignment" Value="Center" />

 

</

 

</

 

</

</

 

 

Setter>

</Style>

<Style x:Key="xamCellCenter" TargetType="{x:Type igDP:CellValuePresenter}">

<Setter Property="HorizontalContentAlignment" Value="Center" />

</Style>

</Window.Resources>

<Grid>

<igDP:XamDataGrid x:Name="xamDataGrid1" Theme="Aero">

 

 

 

<igDP:XamDataGrid.FieldLayouts>

<igDP:FieldLayout>

<igDP:FieldLayout.FieldSettings>

<igDP:FieldSettings CellClickAction="SelectRecord" CellValuePresenterStyle="{Binding Source={StaticResource xamCellCenter}}" LabelPresenterStyle="{Binding Source={StaticResource Epro36HeaderFont}}"/>

</igDP:FieldLayout.FieldSettings>

<igDP:Field Name="FirstName" Label="First&#xa;Name" />

<igDP:Field Name="LastName" Label="Last&#xa;Name" />

<igDP:Field Name="Age" Label="Age" />

</igDP:FieldLayout>

</igDP:XamDataGrid.FieldLayouts>

</igDP:XamDataGrid>

</Grid>

</Window>

 

namespace

 

 

XamDataGridDemo

{

 

 

 

 

 

public partial class MainWindow : Window

{

 

 

 

public MainWindow()

{

InitializeComponent();

 

 

 

List<Person> p = new List<Person>();

p.Add(

 

new Person { LastName = "Adam", FirstName = "Smith", Age = 44 });

p.Add(

 

new Person { LastName = "John", FirstName = "Doe", Age = 20 });

p.Add(

 

new Person { LastName = "Kim", FirstName = "Alex", Age = 32 });

 

 

 

this.xamDataGrid1.DataSource = p;

}

}

 

 

 

public class Person

{

 

 

 

public string FirstName { get; set; }

 

 

 

public string LastName{ get; set; }

 

 

 

public int Age{ get;set;}

}

 

 

 

 

  • 3520
    Verified Answer
    Offline posted

    Hi jama64,

    You really need to set the LabelTextAlignment to "Center" in order to center the labels.

    What you may use, instead of "<Setter Property="HorizontalContentAlignment" Value="Center" />", is the following:

     <igDP:XamDataGrid.FieldSettings>

     

     

     

     

    <igDP:FieldSettings LabelTextAlignment="Center" />

     

     

     

    </igDP:XamDataGrid.FieldSettings>

    Hope this helps.

    Thanks.