0

DataGridTemplateColumn 内に StackPanel があります。このセルの上部のマージンを削除する方法が見つからないようです。

私が使用しているコードは次のとおりです。

        <DataGridTemplateColumn IsReadOnly="True" Header="Description">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel>
                        <StackPanel.Resources>
                            <Style TargetType="{x:Type Label}">
                                <Setter Property="FrameworkElement.Margin" Value="0,0,0,-10" />
                            </Style>
                        </StackPanel.Resources>
                        <Label Content="{Binding Description1}" />
                        <Label Content="{Binding Description2}" />
                    </StackPanel>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>

最初の Label のみがその上にスペースを持っているため、マージンは StackPanel ではなく DataGridTemplateColumn 自体からのもののように見えます。

4

1 に答える 1

0

マージンは、実際にはLabelsではなく、 にありStackPanelます。下マージンを負に設定しているラベルのスタイルを削除するだけで、正しく機能します。

オブジェクトがレンダリングされた後に負のマージンが適用されるように見え、コントロールが設定されている既存の境界の外に移動する可能性があります。あなたの場合、Labelsレンダリングされ、両方が10px下に移動しています

于 2012-03-16T17:24:22.913 に答える