I'm still learning to use the xamDataGrid, so maybe thats just a noob question, but i've tried the examples from this forum and none did work.
I can't set the Cellcontent alignment to right or center.
Here is what i have tried so far.
<Window.Resources> <Style TargetType="{x:Type igDP:CellValuePresenter}" > <Setter Property="HorizontalContentAlignment" Value="Right" /> </Style> </Window.Resources> <DockPanel> <igDP:XamDataGrid Name="grid"> <igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="HorizontalContentAlignment" Value="Center" /> </Style> </igDP:XamDataGrid.Resources> </igDP:XamDataGrid> </DockPanel>
it still looks this way:
My approach ist from this forum:
http://community.infragistics.com/forums/p/13669/70632.aspx
Hi,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
I had the exact same problem and couldn't find an answer anywhere on the forums so I thought I'd post my solution. The key is creating a style with a TargetType of Control which all the editors derive from and can contains the HorizontalAlignment property. Then you can assign it to the editor style (for any editor) in FieldSettings.
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type Control}" x:Key="EditorCenterAligned">
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
</igDP:XamDataGrid.Resources>
...
<igDP:Field.Settings>
<igDP:FieldSettings EditorStyle="{StaticResource EditorCenterAligned}"/>
</igDP:Field.Settings>
So another forum post actually provides a solution to this problem, but unless I'm setting some property incorrectly, I think the CellValuePresenterStyle should be the correct way to do this, not the solution presented here: http://blogs.infragistics.com/forums/t/51899.aspx.
Changing the Editors for ALL content types just seems wrong, wrong, wrong, but since I want to center all the numeric columns in my grid, it works for me.
Here's the solution that seems to work, instead of setting the CellValuePresenter style you set the style of the Editors:
<Grid.Resources> <Style TargetType="{x:Type igEditors:XamTextEditor}" > <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="HorizontalContentAlignment" Value="Center" /> </Style> <Style TargetType="{x:Type igEditors:XamNumericEditor}" > <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="HorizontalContentAlignment" Value="Center" /> </Style> <Style TargetType="{x:Type igEditors:XamDateTimeEditor}" > <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="HorizontalContentAlignment" Value="Center" /> </Style></Grid.Resources>
Here's how my grid looks with these styles applied (for numeric editors):
I'm having the exact same issue. My code is slightly different in that I only want to apply the centered style to a few of the columns so I gave my style a Key and sent the style specifically for individual fields and I get the EXACT same result. If I change other style properties they seem applied (like changing the Background to Blue for example), but the HorizontalContentAlignment property doesn't seem to do anything.
Here's my code:
<igDP:XamDataGrid.Resources> <Style x:Key="CenteredContentStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="HorizontalContentAlignment" Value="Center" /> <Setter Property="Background" Value="Blue" /> </Style> </igDP:XamDataGrid.Resources>
And then for a numerical field I want to have centered:
<igDP:Field Name="MinDuration" Label="Min Dur (s)" Column="2"> <igDP:Field.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource CenteredContentStyle}"> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>