0

Is it possible in a Silverlight Datagrid to manually define where the line break should be? (instead of automatically wrapping to the next line when the border is reached)

This seems like to be the code (source):

 <sdk:DataGridTextColumn 
    Header="Address"
    Width="150"
    Binding="{Binding Address}" >
    <sdk:DataGridTextColumn.ElementStyle>
        <Style TargetType="TextBlock">
            <Setter Property="TextWrapping" Value="Wrap"/>
        </Style>
    </sdk:DataGridTextColumn.ElementStyle>
 </sdk:DataGridTextColumn>

But how do i manually make the line break?

Community
  • 1
  • 1
MMM
  • 311
  • 5
  • 14
  • 30

1 Answers1

0

It is possible in common WPF controls so I believe it should be possible on Silverlight as well. Basically what you need is to target the TextBlock control on each cell of the column, similarly to what is being done to give it a text wrapping style.

As you don't clarify from your question wheter you want to assign the text programmatically or on the XAML, I am going to give you a hint on how to do both.

You can assign the text programmatically using an approach similar to this answer:

txtBlock.Inlines.Add("This is the first paragraph");
txtBlock.Inlines.Add(new LineBreak());
txtBlock.Inlines.Add("This is the second paragraph");

On the other hand, if you want to assign the text directly on XAML, you can use the <LineBreak/> tag directly inside your text, as mentioned in this answer:

<TextBlock>
    This is the first paragraph <LineBreak/>
    This is the second paragraph
</TextBlock>
Community
  • 1
  • 1
Camilo Martinez
  • 1,723
  • 2
  • 21
  • 26
  • well.. I'm adding objects from an observable collection to the Datagrid (programmatically) so how do i access this "txtBlock"? – MMM Apr 16 '13 at 06:10