【问题标题】:WPF Datagrid - Force singleline rowsWPF Datagrid - 强制单行行
【发布时间】:2013-05-20 00:51:12
【问题描述】:

我正在处理 WPF 中的数据网格,但遇到了问题。

向我的 DataGridTextColumn 添加多行字符串时,行的高度会扩大以适合整个文本。我希望行高始终保持不变,即只显示第一行。

有人知道解决办法吗?似乎是一个足够简单的任务,但我还没有找到任何关于这个主题的有价值的东西。

这是我的 XAML:

<DataGrid Grid.Row="0" AutoGenerateColumns="False" HorizontalAlignment="Stretch" Name="dgPosts" VerticalAlignment="Stretch"
                            SelectionMode="Single" SelectionUnit="FullRow" ItemsSource="{DynamicResource LogPosts}" CanUserAddRows="False"
                            IsReadOnly="True" GridLinesVisibility="Vertical" RowHeaderWidth="0" Margin="0,0,0,0"
                            CanUserReorderColumns="True" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="True" SelectionChanged="dgPosts_SelectionChanged">
   <DataGrid.Columns>
         <DataGridTextColumn Header="Tidpunkt" Width="120" Binding="{Binding Path=TimeStr}"/>
         <DataGridTextColumn Header="Posttyp" Width="55" Binding="{Binding Path=PostTypeStr}" CellStyle="{StaticResource CenterCellStyle}"/>
         <DataGridTextColumn Header="Beskrivning" Width="*" Binding="{Binding Path=Text}"/>
   </DataGrid.Columns>
   <DataGrid.RowStyle>
         <Style TargetType="DataGridRow">
            <Setter Property="Background" Value="{Binding Path=Color}"/>
            <Style.Triggers>
               <Trigger Property="DataGridRow.IsSelected" Value="True" >
                     <Setter Property="Background" Value="Black" />
               </Trigger>
            </Style.Triggers>
         </Style>
   </DataGrid.RowStyle>
   <DataGrid.CellStyle>
         <Style TargetType="DataGridCell">
            <Setter Property="BorderThickness" Value="0"/>
         </Style>
   </DataGrid.CellStyle>
   <DataGrid.Resources>
         <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
   </DataGrid.Resources>
</DataGrid>

提前致谢!

【问题讨论】:

  • 尝试为您的 DataGridCell 设置高度

标签: c# wpf xaml datagrid row


【解决方案1】:

您只需在 DataGrid 中设置行高:

<DataGrid RowHeight="50">
</DataGrid>

就是这样。

【讨论】:

  • 一个又好又快的解决方案,虽然我猜这可能会成为不同字体大小的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-05
  • 2012-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-29
相关资源
最近更新 更多