gpt4 book ai didi

c# - WPF DataGrid 行高

转载 作者:行者123 更新时间:2023-11-30 15:01:46 24 4
gpt4 key购买 nike

我在 WPF 项目中有一个数据网格。我已将列宽设置为具有最大限制,
我希望数据同样被拉伸(stretch)以适合行。但这并没有发生......内容只是保持相同的大小并且单元格被截断。有任何想法吗?

代码如下:

<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>

最佳答案

尝试使用 TextBlock。它应该自动将内容包装成您想要的大小。

  <DataGridTemplateColumn Width="*" Header="Column 2">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=task_req_date}" TextWrapping="Wrap" AcceptsReturn="true" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

关于c# - WPF DataGrid 行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13589898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com