Datagrid行未与列标题对齐

时间:2013-11-05 11:03:27

标签: c# wpf datagrid

我遇到与此问题相同的问题:

DataGrid column headers not aligned with data

我所拥有的是在我的窗口中的数据网格,但在scrollviewer中。我想要做的是将我的滚动查看器与此数据网格转移到另一个窗口。现在它工作得很好,但是我的数据网格在另一个窗口中没有对齐。 有什么可以解决这个问题? PS:如果您需要提供任何代码,请与我们联系。

更新

<ScrollViewer Grid.Row="1" Name="inputReportScrollViewer" Height="22cm" Width="19cm" HorizontalAlignment="Center" >

<Grid>
   <Grid.RowDefinitions>
     <RowDefinition Height="auto" />
   </Grid.RowDefinitions>

   <Grid Grid.Row="0">
                <DataGrid Name="InputReportDataGrid"  AutoGenerateColumns="False" CanUserAddRows="false" >
                    <DataGrid.ColumnHeaderStyle>
                        <Style TargetType="Control">
                            <Setter Property="FontSize" Value="10"/>
                        </Style>
                    </DataGrid.ColumnHeaderStyle>
                    <DataGrid.RowStyle>
                        <Style TargetType="Control">
                            <Setter Property="FontSize" Value="10"/>
                        </Style>
                    </DataGrid.RowStyle>
                    <DataGrid.Columns>
                        <!--<DataGridTextColumn Header="RedniBroj" />-->
                        <DataGridTextColumn Header="UCode" Binding="{Binding Path= tblGood.UCode}" />
                        <DataGridTextColumn Header="Good Name" Binding="{Binding Path= tblGood.Name}" />
                        <DataGridTextColumn Header="Measurement&#x0a; Unit" Binding="{Binding Path= tblGood.MeasurementUnit}" />
                        <DataGridTextColumn Header="Amount" Binding="{Binding Path= Amount, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Input Price" Binding="{Binding Path= InputPrice, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Input Value" Binding="{Binding Path= InputValue, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Suggested Price" Binding="{Binding Path= SuggestedPrice, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Suggested&#x0a; Value" Binding="{Binding Path= SuggestedValue, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Vat" Binding="{Binding Path= VatBase}" />
                        <DataGridTextColumn Header="Vat Value" Binding="{Binding Path= VatValue, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="Suggested&#x0a; Value&#x0a; Without&#x0a; Vat" Binding="{Binding Path= SuggestedValueWithoutVat, Converter={StaticResource moneyConverter}}" />
                        <DataGridTextColumn Header="RUC" Binding="{Binding Path= SuggestedValueWithoutVat, Converter={StaticResource moneyConverter}}" />
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>
          </Grid>
</ScrollViewer>

2 个答案:

答案 0 :(得分:1)

尝试设置HeadersVisibility =无

答案 1 :(得分:0)

为列标题添加自定义样式

<Style x:Key="{x:Type DataGridColumnHeadersPresenter}" TargetType="{x:Type DataGridColumnHeadersPresenter}">
    <Setter Property="Grid.ColumnSpan" Value="2" />
</Style>