Posted 9 years ago by Niclas Lindblom
Version: 10.2.0530
Avatar
Hi,

I am evaluateng the WPF suite and datagrid contrib and have 2 questions

1. How do I align the conent of a cell to be centered. Have tried using a style

<datagrid:ThemedDataGrid.Resources>
<Style x:Key="CenterCellStyle" TargetType="{x:Type toolkit:DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type toolkit:DataGridCell}">
<Grid>

<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</datagrid:ThemedDataGrid.Resources>

But this seem to break the current Theme and cells get different font colour and background for the cells in the selected Row which are set to use the style. Is there a better way of doing this or what am I missing (My XAML skills could be better) ?


2. I have set my grid to "fullrow" selection, how do I disable the column header to change colour for the column that the cell in the row was in ? Would like the header colour to be static and not indicate what particular column was clicked when selecting a Row

Regards

Niclas

Comments (7)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Niclas,

1. We provide a custom style for DataGridCell to achive the theme. You should be able to base your Style on ours, so something like:
xmlns:themes="http://schemas.actiprosoftware.com/winfx/xaml/themes"
...
<Style x:Key="CenterCellStyle" TargetType="{x:Type toolkit:DataGridCell}"
    BasedOn="{StaticResource {x:Static themes:DataGridCommonDictionary.DataGridCellStyleKey}}">
    ...
</Style>
2. You might be able to disabled the attached property that tracks the focus by setting datagrid:FocusBehavior.TrackingModes to None.


Actipro Software Support

Posted 9 years ago by Niclas Lindblom
Avatar
Many thanks for replying. The new style helped somewhat, I now get the correct colour on the fonts, but backcolour is diffferent. Here is the code I got

   <Style x:Key="CenterCellStyle" TargetType="{x:Type toolkit:DataGridCell}" BasedOn="{StaticResource {x:Static themes:DataGridCommonDictionary.DataGridCellStyleKey}}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type toolkit:DataGridCell}">
                        <Grid>
                            <ContentPresenter  HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

With regards of your suggestion for my second question, can you please expand a bit on where the code datagrid:FocusBehavior.TrackingModes should go ?

Many thanks

Niclas
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Niclas,

The problem is you are redefinig the control template, and effectively removing the Border that provides the background. You can download the source for the DataGrid control at http://actipro.codeplex.com.

The style in question is in the OfficeCommon.xaml file, with the key "{x:Static datagridThemes:DataGridCommonDictionary.DataGridCellStyleKey}". You can use that as a basis, but based on your original question, you can probably just set HorizontalContentAlignment to Center in a Setter and leave the default control template.


Actipro Software Support

Posted 9 years ago by Niclas Lindblom
Avatar
A sample on a HorizontalContentAlignment Setter would be very useful..

Many thanks

Niclas
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Niclas,

It would be:

<Setter Property="HorizontalContentAlignment" Value="Center" />


Actipro Software Support

Posted 9 years ago by Niclas Lindblom
Avatar
That worked like a charm, many thanks.

If you can give me a clue on how to test the proposed solution from the first answer below on how to not indicate what column is clicked in the header when a row is selected in Fullrow mode

2. You might be able to disabled the attached property that tracks the focus by setting datagrid:FocusBehavior.TrackingModes to None.

I dont get where to insert this code..

Many thanks

Niclas
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Niclas,

You'd need to set that attached property directly on the DataGrid. That behavior tracks the focus, and is used to provide the header highlight you want to disable. So if you disable the focus tracking, the header highlight will also be disabled.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.