Hi,
I would like to change the text alignement in a cell. My first idea is to set the Template for CellValuePresenter and define my own TextBlock. It works but I loose much of the functionality of the XamDataGrid. Editing is no more possible (without coding), selection, ...
So I took a look in your samples an tried this:
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Foreground" Value="{DynamicResource GeneralForeground}" />
<Setter Property="Background" Value="{DynamicResource GeneralBackground}" />
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
The Text is centered but the Background color no more fills the whole cell. Then I tried this:
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="TextBlock.TextAlignment" Value="Center" />
Now the background color fills the whole cell but the text is only centered when editing. I think I'm missing something...
Could someone help me?
Thanks,
Daniel
PS: In the preview the code is not easily readable... How shoud l insert code snippets correctly in the forum?
Hello,
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.
Thanks for your help Stefan!
Hello Daniel,
Since the FieldSettings Property is a Collection and doesn’t have Style, the thing you can do is create an instance of FieldSettings as StaticResouce and set it to the XamDataGrid’s FieldSettings Property. I also attached a sample project demonstrating this approach. Please let me now if it helps you or you need further assistance on this matter.
Looking forward for your reply.
Hi Stefan,
Thanks for your answer. I think this is the right way. When I set the LabelTextAlignment in the Settings it works. However, I don't want to set it to every column but in a style. I tried following code but it doesn't work... Any idea?
<Style TargetType="{x:Type igDP:FieldSettings}"> <Setter Property="LabelTextAlignment" Value="Center" /></Style>
Thanks
Another possible way to align the labels is to set the XamDataGrid's FieldSettings' LabeltextAlignment Property.
Hope this helps you.