I have a DataGridTextColumn ElementStyle as follows:
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Style.Setters>
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush>
<GradientStop Color="Black" Offset="0" />
<GradientStop Color="White" Offset="2" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="White" />
<Setter Property="TextWrapping" Value="Wrap" />
</Style.Setters>
</Style>
</DataGridTextColumn.ElementStyle>
I will need a cell in this column to display text in multiple lines but the number of lines should not exceed 3. The TextBlock does not have a MaxLines property so I cannot specify it directly. What’s more the TextBlock does not have a Template property so I can’t use a border less, read-only TextBox either. What can I do here?
Well I think the most simple way to achieve this is to use a TemplateColumn. Here is a quick sample : Second Column is a TextColumn where you can’t do much, first column is a TemplateColumn with a TextBox that will be borderless and readonly, and MaxLines set to 3 :