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?
I found a solution:
I tried the same for the LabelPresenter but it doesn't work. Any idea?
Hello,
Thank you for your post. I have been looking into it and I can suggest you create a Style for the LabelPresenter and add EventSetter for its Loaded event like this:
<Style TargetType="{x:Type igDP:LabelPresenter}"> <EventSetter Event="Loaded" Handler="lpLoaded"/> </Style>
And add the following code ion the code behind:
private void lpLoaded(object sender, RoutedEventArgs e) { (Utilities.GetDescendantFromType(sender as DependencyObject, typeof(TextBlock), true) as TextBlock).HorizontalAlignment = HorizontalAlignment.Center; }
Also here you can see how to paste your code in the community:
http://community.infragistics.com/forums/p/28814/327078.aspx
Hope this helps you.
Hello Daniel,
Another possible way to align the labels is to set the XamDataGrid's FieldSettings' LabeltextAlignment Property.
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
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.
Thanks for your help Stefan!
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.