我在 WPF 项目中有一个数据网格。我已将列宽设置为具有最大限制,
并且我希望数据同样被拉伸以适合行。但这不会发生......内容只是保持相同的大小并且单元格被切断。有任何想法吗?
这是代码:
<DockPanel>
<DataGrid x:Name="nirGrid" x:Uid="nirGrid" AutoGenerateColumns="False" AlternationCount="2" SelectionMode="Single" DockPanel.Dock="Top" Margin="10,50,10,50" FlowDirection="RightToLeft" ColumnWidth="SizeToCells" CanUserSortColumns="False" CanUserResizeColumns="False" CanUserReorderColumns="False" GridLinesVisibility="None" HeadersVisibility="None" SelectionUnit="Cell" VerticalAlignment="Stretch" EnableRowVirtualization="False" IsReadOnly="True" RowDetailsVisibilityMode="Visible" MinRowHeight="0" CanUserResizeRows="True" RowHeaderWidth="0">
<DataGrid.Style>
<Style>
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
</Style>
</DataGrid.Style>
<DataGrid.Columns >
<DataGridTextColumn Binding="{Binding Path=task_desc}" IsReadOnly="True" Header="test1" Width="SizeToCells" MaxWidth="330" >
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Path=task_req_date}" IsReadOnly="True" Header="test2" Width="SizeToCells" MaxWidth="70" >
</DataGridTextColumn>
<DataGridTemplateColumn Header="delete" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="delete" ToolTip="delete" Opacity="0.8" Click="Button_Click" MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave">
<Button.Template>
<ControlTemplate>
<Border HorizontalAlignment="Center" VerticalAlignment="Center">
<Image Source="/exhibits;component/Images/exit1.png" Width="15" Height="15" />
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>