1
votes

I have a wpf 4.5 application that has a datagrid in a usercontrol. I designed the style for the datagrid in Blend but when I copy the style into my VS 2012 project it is not working properly.

Here is what the base style looks like in Blend:

Blend DataGrid Style

Please note the color of the text in the selected row (green) and the padding around the textbox that is being edited

Now here is what the same style looks like Visual Studio 2012:

VS Datagrid Style

So the highlighted text from the selected row is the same color as the background (making it invisible), and I can't change the textbox bordercolor or margin to match the blend style.

here is the cell style:

<Style TargetType="{x:Type DataGridCell}">
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridCell}">
                <Border x:Name="border"
                        BorderBrush="Transparent"
                        BorderThickness="1"
                        Background="Transparent"
                        SnapsToDevicePixels="True"
                        Margin="15,10,15,10">
                    <ContentPresenter Name="CellContent" SnapsToDevicePixels="True" />
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Foreground" Value="Green"/>
                    </Trigger>
                    <Trigger Property="IsKeyboardFocusWithin" Value="True">
                        <Setter Property="BorderBrush" TargetName="border" Value="#FFD8D8D8"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>                
        </Setter.Value>
    </Setter>
</Style>

so you can see that the trigger marking green as the foregorund color works in blend but not visual studio. I think it is a system color that is overriding the trigger some how but I am not sure how to track this down.

Can someone please help me correct this style problem by setting the selected row text color and textbox border/margins.

This is a link to the entire datagrid style resource dictionary

thanks in advance

2
Link to the datagrid style is dead. Is it possible to update it ?cydef

2 Answers

1
votes

Hi I tried your Style and on my Machine the ForegroundColor changed to Green... But if it doesn´t work in your DevEnvironment you could try overriding the SystemColor for the selected-row text!

add this to your style and remove the trigger

<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Green" />
1
votes

So it turned out to be a conflict of the DataGridCell style. I had a DataGridCell style applied without key name to all datagrid cells. Then I created another cell style based on the one mentioned above But for some reason if I tried to apply this cell style to specific column declarations in the datagrid the style would break. So I had to remove the "based on styles" and find another way to do column specific formatting.

EDIT: see style here, too long to post DataGridStyle