[英]Allow row to grow and text wrap using datagrind in Material Design
I am struggling to find how I can have my rows expand in a data grid using material design.我正在努力寻找如何使用材料设计在数据网格中扩展我的行。 Basically if a cell become full I need the string to wrap in the cell and allow the row to expand to fit this.基本上,如果一个单元格变满,我需要将字符串包裹在单元格中并允许该行扩展以适应它。 The data is pulled in from a SQL database and thus this is the XAML I currently have;数据是从 SQL 数据库中提取的,因此这是我目前拥有的 XAML;
<DataGrid x:Name="tblProcesses" AutoGenerateColumns="False" CanUserAddRows="True"
BorderThickness="1" BorderBrush="{DynamicResource PrimaryHueMidBrush}" DockPanel.Dock="Top">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding order, UpdateSourceTrigger=PropertyChanged}" ClipboardContentBinding="{x:Null}" Header="Order" Width="80"/>
<DataGridTextColumn Binding="{Binding title, UpdateSourceTrigger=PropertyChanged}" ClipboardContentBinding="{x:Null}" Header="Process" Width="*"/>
<DataGridTextColumn Binding="{Binding description, UpdateSourceTrigger=PropertyChanged}" ClipboardContentBinding="{x:Null}" Header="Description" Width="2*"/>
<DataGridTextColumn Binding="{Binding imageURL, UpdateSourceTrigger=PropertyChanged}" ClipboardContentBinding="{x:Null}" Header="Image URL" Width="100"/>
<DataGridTextColumn Binding="{Binding timeTaken, UpdateSourceTrigger=PropertyChanged}" ClipboardContentBinding="{x:Null}" Header="Time Taken" Width="100"/>
</DataGrid.Columns>
</DataGrid>
Also if the way I bind the data the most effective way?还有如果我绑定数据的方式最有效呢? It is working as I expect it (minus the text wrapping), however I wanted to see how the pros would tackle this.它按我的预期工作(减去文本换行),但是我想看看专业人士如何解决这个问题。
You can do this and specify ElementStyle
for specific column.您可以执行此操作并为特定列指定ElementStyle
。
<DataGrid.Columns>
<DataGridTextColumn Header="Wrapped & centered" Binding="{Binding field}">
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
Or you can do this by defining the style in window resource.或者您可以通过在窗口资源中定义样式来实现。
<Window.Resources>
<Style TargetType="{x:Type TextBlock}" x:Key="WrapText">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</Window.Resources>
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="False" Header="Address"
Binding="{Binding Address}" ElementStyle="{StaticResource WrapText}" Width="150"/>
</DataGrid.Columns>
It will wrap the content of cell instead of cutting or clipping it.它将包裹单元格的内容而不是剪切或剪切它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.