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.