我有一個數據網格下面給出:WPF數據網格的高度和寬度的調整問題
<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>
這是模板列的樣式:在datagridcellstyle
我已確定的細胞的值作爲寬度
<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>
雖然和高度爲50.但是,當我加載9行datagrid它的高度顯示452而不是450(9 * 50),並以同樣的方式顯示更多的寬度。
爲什麼它顯示像那樣?
如何避免?