Datagrid行错误对齐

时间:2012-02-01 11:21:39

标签: c# .net wpf .net-4.0 wpfdatagrid

我遇到了使用WPF Datagrid的奇怪行为。正如您在附加的图片中看到的那样,有时会出现一行显示错误的“对齐”。

Wrong Alignment

以下是我的Datagrid的XAML代码:

<DataGrid Name="DataGridDocs" Margin="10" ItemsSource="{Binding}" AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="True" FontSize="15" IsReadOnly="True" HeadersVisibility="Column" AlternatingRowBackground="#FF3CC4A9">
            <DataGrid.ColumnHeaderStyle>
                <Style TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="FontWeight" Value="Bold"/>
                </Style>
            </DataGrid.ColumnHeaderStyle>
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem x:Name="menuSelezionaTutti" Header="Seleziona Tutti" Click="menuSelezionaTutti_Click" FontSize="15" />
                    <MenuItem x:Name="menuDeselezionaTutti" Header="Annulla Selezione" Click="menuDeselezionaTutti_Click" FontSize="15" />
                </ContextMenu>
            </DataGrid.ContextMenu>
            <DataGrid.Columns>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ContentControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalAlignment="Center">
                                <CheckBox Name="CheckBoxSelected" IsChecked="{Binding Path=SELECTED, Mode=Default, UpdateSourceTrigger=PropertyChanged}" />
                            </ContentControl>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Binding="{Binding Path=DOCUMENT_ID}" Header="ID" />
                <DataGridTextColumn Binding="{Binding Path=DESCR}" Header="TIPOLOGIA" />
                <DataGridTextColumn Binding="{Binding Path=COGNOME}" Header="COGNOME" />
                <DataGridTextColumn Binding="{Binding Path=NOME}" Header="NOME" />
                <DataGridTextColumn Binding="{Binding Path=DATA}" Header="DATA" />
                <DataGridTextColumn Binding="{Binding Path=FILENAME}" Header="FILE" />
                <DataGridTextColumn Binding="{Binding Path=COD_PRATICA}" Header="CODICE PRATICA" />
                <DataGridTextColumn Binding="{Binding Path=COD_CARTA}" Header="CODICE CARTA" />
                <DataGridTextColumn Binding="{Binding Path=COD_IVA}" Header="CODICE IVA" />
                <DataGridTextColumn Binding="{Binding Path=COD_CLIENTE}" Header="CODICE CLIENTE" />
                <DataGridTextColumn Binding="{Binding Path=COD_DOCUMENTO}" Header="CODICE DOCUMENTO" />
                <DataGridTextColumn Binding="{Binding Path=DOCUMENT_ID}" Header="DOCUMENT_ID" Visibility="Hidden" />
                <DataGridTextColumn Binding="{Binding Path=FOLDER}" Header="FOLDER" Visibility="Hidden" />
            </DataGrid.Columns>
        </DataGrid>

1 个答案:

答案 0 :(得分:0)

删除属性HeadersVisibility =“Column”并改用RowHeaderWidth = 0