开发者

Apply LayoutTransform to DataGridTextColumn

I've got 开发者_运维技巧a DataGrid containing some DataGridTextColumns 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).


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜