pat
pat

Reputation: 236

WPF linebreak problems

I have a TextBlock and want to show information from the database. I wan't to display the text like this:

Task for Day xy
- blabla
- blabla 
- more blablabla

Somehow I need to include a character for the newlines.. I thoug about \n.. so the text in the database would look like:

Task for Day xy\n- blabla\n- blabla\n- more blablabla

doesn't work.

I tried and searched online for hours.. no solution how to do that. Also this doesn't work:

Task for Day xy<LineBreak />- blabla<LineBreak />- blabla<LineBreak />- more blablabla

the application shows exactly that string from the database without new lines..

here the part of the xaml:

<Grid>
  <Grid.ColumnDefinitions>
      <ColumnDefinition Width="100" />
      <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>
  <TextBlock Grid.Column="1" Text="{Binding Date, StringFormat={}{0:dd.MM.yyyy}}" Margin="6" />
  <TextBlock Grid.Column="2" Text="{Binding Notes}" Margin="6" />
</Grid>

any ideas?

Upvotes: 0

Views: 618

Answers (2)

Heinzi
Heinzi

Reputation: 172260

Just include a regular newline character in the text, no fancy escape sequences or XML tags:

 string fromDb = ... // get string from DB
 myPropertyWhichIsBoundToWpf = fromDb.Replace("hereShouldBeALinebreak", 
                                              System.Environment.NewLine);

Upvotes: 0

Brent Stewart
Brent Stewart

Reputation: 1840

I would not recommend storing the line breaks in the database, as line breaks will not be the same across platforms. I would just add the line breaks before displaying using System.Environment.NewLine.

Upvotes: 2

Related Questions