Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
290
Change text alignement in a cell
posted

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:

 

 

 

<Style TargetType="{x:Type igDP:CellValuePresenter}">

 

 

 

<Setter Property="Foreground" Value="{DynamicResource GeneralForeground}" />

 

 

 

<Setter Property="Background" Value="{DynamicResource GeneralBackground}" />

 

 

 

<Setter Property="HorizontalAlignment" Value="Stretch" />

 

 

 

<Setter Property="TextBlock.TextAlignment" Value="Center" />

 

 

 

</Style>

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?

Parents Reply
  • 290
    Offline posted in reply to Stefan

    Hi Stefan,

    Thanks for your answer. My problem is that the styles are in a ResourceDictionary in another assembly which I references. So I can't add an event handler. Is there another way to do that ?

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:igDP="http://infragistics.com/DataPresenter">

        <Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="LastFieldCellPresenter">
            <Setter Property="Foreground" Value="{DynamicResource GeneralForeground}" />
            <Setter Property="Background" Value="{DynamicResource GeneralBackground}" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="BorderBrush" Value="{DynamicResource GeneralForeground}" />
            <Setter Property="BorderThickness" Value="1,0,0,0" />
        </Style>
        <Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="DefaultCellValuePresenter">
            <Setter Property="Foreground" Value="{DynamicResource GeneralForeground}" />
            <Setter Property="Background" Value="{DynamicResource GeneralBackground}" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="BorderBrush" Value="{DynamicResource GeneralForeground}" />
            <Setter Property="BorderThickness" Value="1,0,0,1" />
        </Style>
        <Style TargetType="{x:Type igDP:LabelPresenter}" x:Key="DefaultLabelPresenter">
            <Setter Property="Foreground" Value="{DynamicResource GeneralForeground}" />
            <Setter Property="Background" Value="{DynamicResource GeneralBackground}" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="BorderBrush" Value="{DynamicResource GeneralForeground}" />
            <Setter Property="BorderThickness" Value="1,0,0,1" />
        </Style>

        <Style TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource DefaultCellValuePresenter}" />
        <Style TargetType="{x:Type igDP:LabelPresenter}" BasedOn="{StaticResource DefaultLabelPresenter}" />

    </ResourceDictionary>

    Thanks,

    Daniel

Children