在数据网格中显示没有换行符

时间:2019-03-05 11:48:26

标签: c# wpf xaml

  

我有一个datagrid,它绑定到了数据表,问题是它以多行形式显示每一行,例如:

enter image description here

  

XAML如下:

<DataGrid    
     DataContext="{Binding DashBoardUCVM, Source={StaticResource Locator}}" 
     Foreground="Black"
     FontSize="16"                
     Background="White"
     IsReadOnly="True"
     SelectedIndex="{Binding SelectedIndexDDG}"
     SelectedValue="{Binding SelectionValueDDG}" 
     ItemsSource="{Binding JobsViewDG}">        
</DataGrid>
  

我尝试过像this的答案,并添加了RowHeight="50",但是我得到了:

enter image description here

  

即它仅显示内容的顶部。我需要类似的东西:

enter image description here

2 个答案:

答案 0 :(得分:1)

我不太了解您想在这里完成什么。但是我认为在数据网格中显示多行存在问题。

正如我所看到的,问题不在于datagrid是您发送的数据。尝试处理数据,然后再将其传递到数据网格。当原始数据不适合我时,我通常会使用DataTable。在数据表中,我可以根据需要修改它的值,撤回或添加信息确实很简单,然后我可以通过绑定或简单地通过DataTable.AsDataView()将其直接传递给它的ItemSource来将其粘贴到DataGrid。 / p>

PS:请注意,必须在DataTAble和DataGrid的列之间进行绑定(datagrid列的内容必须与datatable标头具有相同的绑定名称)

答案 1 :(得分:0)

如果我正确理解了您的问题,则希望摆脱包装,可以使用以下方法实现包装:

<DataGrid ...>
<DataGrid.Resources>
    <Style TargetType="{x:Type TextBlock}">
        <Setter Property="TextWrapping" Value="NoWrap"/>
    </Style>
</DataGrid.Resources>
...

如此处WPF DataGrid Cell Text Wrapping - set to NoWrap (False)

您可以指定要开始使用的宽度,其余部分将隐藏在列的右侧。

相关问题