我有一个数据网格,如下所示:
<DataGrid SizeChanged="dgvMap_SizeChanged" Padding="0,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Center" GridLinesVisibility="None" Background="Transparent"
BorderBrush="Transparent" IsReadOnly="True" ItemsSource="{Binding IsAsync=True}" EnableColumnVirtualization="True"
EnableRowVirtualization="True" AutoGenerateColumns="True" AutoGeneratingColumn="dgvMap_AutoGeneratingColumn"
CanUserAddRows="False" CanUserSortColumns="true" CanUserDeleteRows="False" HeadersVisibility="None"
Name="dgvMap" SelectionMode="Single" Panel.ZIndex="0" Margin="0,0,0,0" VirtualizingStackPanel.VirtualizationMode="Standard"
PreviewMouseDown="dgvMap_PreviewMouseDown" >
<!--for removing the blue color bkground default for row selection-->
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
</DataGrid.Resources>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Padding" Value="0"/>
<Setter Property="Height" Value="50" />
<Setter Property="Width" Value="50" />
</Style>
</DataGrid.CellStyle>
</DataGrid>
这是模板列的样式:
<DataTemplate x:Key="MyDataTemplate" DataType="DataRowView">
<StackPanel Background="Transparent">
<Image Tag="{Binding}" Name="Layer0" Margin="0,0,0,0" Panel.ZIndex="1"
ToolTipService.HasDropShadow="True" ToolTipService.ShowDuration="20000" ToolTipService.InitialShowDelay="200" >
<Image.Resources>
<Style TargetType="{x:Type Image}">
<Setter Property="Source" Value="{Binding Converter={StaticResource IntToImageConverter}, ConverterParameter = Layer0}" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<!-- Hover image -->
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Source" Value="D:\small.png"/>
</Trigger>
</Style.Triggers>
</Style>
</Image.Resources>
</Image>
</StackPanel>
</DataTemplate>
虽然在datagridcellstyle
我已将单元格值定义为宽度和高度为 50。但是当我加载具有 9 行的数据网格时,它的高度显示为 452 而不是 450(9*50),并且以同样的方式宽度也显示更多。
为什么会这样显示??
怎么避免呢??