DataGrid RowHeaderTemplate中的垂直对齐。

| 这是我使用的代码。我尝试将VerticalAlignment设置为Top,但是当显示行详细信息(展开显示)时,按钮将移至行的中心。
<DataGrid.RowHeaderTemplate>
<DataTemplate>
    <Grid>
        <Button x:Name=\"c_expandCollapseBtn\" Cursor=\"Hand\" Click=\"OnExpandCollapseClick\" Content=\"+\"
                MinHeight=\"8\" MinWidth=\"15\" VerticalAlignment=\"Top\" HorizontalAlignment=\"Left\"/>
    </Grid>
</DataTemplate> 
</DataGrid.RowHeaderTemplate>
    
已邀请:
        您正在设置按钮内容的对齐方式。 这是一种将行标题内容演示者置于顶部的样式。 编辑
    <Style x:Key=\"DataGridRowHeaderStyle\" TargetType=\"{x:Type DataGridRowHeader}\">
        <Setter Property=\"Template\">
            <Setter.Value>
                <ControlTemplate TargetType=\"{x:Type DataGridRowHeader}\">
                    <Grid>
                        <Microsoft_Windows_Themes:DataGridHeaderBorder BorderBrush=\"{TemplateBinding BorderBrush}\" BorderThickness=\"{TemplateBinding BorderThickness}\" Background=\"{TemplateBinding Background}\" IsPressed=\"{TemplateBinding IsPressed}\" IsHovered=\"{TemplateBinding IsMouseOver}\" IsSelected=\"{TemplateBinding IsRowSelected}\" Orientation=\"Horizontal\" Padding=\"{TemplateBinding Padding}\" SeparatorBrush=\"{TemplateBinding SeparatorBrush}\" SeparatorVisibility=\"{TemplateBinding SeparatorVisibility}\">
                            <StackPanel Orientation=\"Horizontal\">
                                <ContentPresenter SnapsToDevicePixels=\"{TemplateBinding SnapsToDevicePixels}\" VerticalAlignment=\"Top\"/>
                                <Control SnapsToDevicePixels=\"false\" Template=\"{Binding ValidationErrorTemplate, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}\" Visibility=\"{Binding (Validation.HasError), Converter={StaticResource bool2VisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}\"/>
                            </StackPanel>
                        </Microsoft_Windows_Themes:DataGridHeaderBorder>
                        <Thumb x:Name=\"PART_TopHeaderGripper\" Style=\"{StaticResource RowHeaderGripperStyle}\" VerticalAlignment=\"Top\"/>
                        <Thumb x:Name=\"PART_BottomHeaderGripper\" Style=\"{StaticResource RowHeaderGripperStyle}\" VerticalAlignment=\"Bottom\"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
        您可以使用探听工具-这将帮助您调试视觉元素的布局。网格本身似乎与中心对齐。将VerticalAlignment = \“ Top \”放置到网格。     

要回复问题请先登录注册