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" />
</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
Name" />
<igDP:Field Name="LastName" Label="Last
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 });
new Person { LastName = "John", FirstName = "Doe", Age = 20 });
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;}
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.