Fre*_*rna 4 c# wpf xaml datagrid row
我正在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>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
您只需在DataGrid中设置行高:
<DataGrid RowHeight="50">
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
就是这样.