views:

13

answers:

1

I've got a DataGrid containing some DataGridTextColumn and would like to apply a simple LayoutTransform to the cells, but not the header.

Problem is, DataGridTextColumn does not offer LayoutTransform.

I was able to apply LayoutTransformation to a DataGridTemplateColumn, but I lost a whole lot of functional and was unable to build it back.

My sample so far was:

<DataGridTemplateColumn Header="Satz">
  <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
      <TextBlock Margin="3,0,4,1" Text="{Binding Satz}">
        <TextBlock.LayoutTransform>
          <ScaleTransform ScaleX="1.4" ScaleY="1.4"/>
        </TextBlock.LayoutTransform>
      </TextBlock>
    </DataTemplate>
  </DataGridTemplateColumn.CellTemplate>
  <DataGridTemplateColumn.CellEditingTemplate>
    <DataTemplate>
      <TextBox BorderThickness="0" Text="{Binding Satz, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}">
        <TextBox.LayoutTransform>
          <ScaleTransform ScaleX="1.4" ScaleY="1.4"/>
        </TextBox.LayoutTransform>
      </TextBox>
    </DataTemplate>
  </DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>

I'm looking for one of two ways:
- either to scale DataGridTextColumn.
Or, if thats not possible to
- change the DataGridTemplateColumn so it supports all the functionalty of the DataGridTextColumn (Sorting, editing) and, most important, offers the same user interface (right now the editing in the templatecolumn works different from the textcolumn).

+1  A: 

How about putting the LayoutTransform in a CellStyle?

    <DataGrid x:Name="dg">
        <DataGrid.Resources>
            <Style x:Key="myCellStyle" TargetType="DataGridCell">
                <Setter Property="LayoutTransform">
                    <Setter.Value>
                        <ScaleTransform ScaleX="1.4" ScaleY="1.4"/>
                    </Setter.Value>
                </Setter>
            </Style>
        </DataGrid.Resources>
        <DataGrid.Columns>
            <DataGridTextColumn CellStyle="{StaticResource myCellStyle}" Binding="{Binding Field}"/>
        </DataGrid.Columns>
    </DataGrid>
karmicpuppet
Woa, cool, finally a clear example how to use CellStyle.
Sam
But somehow it does not work for me, I get an exception "" is not a valid value for property "CellStyle" (my translation from german). Looks like the staticresource somehow is empty?
Sam
Hmm... not sure why you're getting that error. Did you copy the XAML above as is or did you make any changes to it?
karmicpuppet
Oh dang, sorry, my mistake - I had an extra line of some other stuff I tried and it contained the offending empty CellStyle - after your question I scrubbed my code and it worked!
Sam