471,330 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

wpf - add newline to wrappanel ?

Hello,

I'm trying to create the equivalent of a textbox which could format
different kind of "values" using a string.
Currently i can do this: (myObject is an ItemsControl)

<myObject>
<myObject.Items>
The value of abc is:
<SomeHandler DataContext="{Binding abc}">
The value of def is:
<SomeHandler DataContext="{Binding def}">
<myObject.Items>
</myObject>

A TemplateSelector is used to transform each element into a TextBlock,
and a WrapPanel is used to layout the textblocks, so that resizing the
window keeps all textblocks displayed to user, like a the text in a
web browser.

My question is: how can I do to insert NewLines manually ? Web
browsers have an auto wrap feature, but they also include <br /tags.
What's the easiest way to implement this ? And if it is not posible,
any idea i could do this with or without breaking my code ?

Thanks in advance.
Jun 27 '08 #1
1 7369
"Vivien Parlat" <po****@gmail.comwrote in message
news:b3**********************************@d45g2000 hsc.googlegroups.com...
Hello,

I'm trying to create the equivalent of a textbox which could format
different kind of "values" using a string.
Currently i can do this: (myObject is an ItemsControl)

<myObject>
<myObject.Items>
The value of abc is:
<SomeHandler DataContext="{Binding abc}">
The value of def is:
<SomeHandler DataContext="{Binding def}">
<myObject.Items>
</myObject>

A TemplateSelector is used to transform each element into a TextBlock,
and a WrapPanel is used to layout the textblocks, so that resizing the
window keeps all textblocks displayed to user, like a the text in a
web browser.

My question is: how can I do to insert NewLines manually ? Web
browsers have an auto wrap feature, but they also include <br /tags.
What's the easiest way to implement this ? And if it is not posible,
any idea i could do this with or without breaking my code ?

Thanks in advance.
If you just want to force a new line within a TextBlock you can do this:
<TextBlock>Line1<LineBreak />Line2</TextBlock>
Or, in code:
myTextBox.Text = "Line1" + Environment.NewLine + "Line 2";

However, if you want to force the WrapPanel to wrap after a particular text
block then I don't know of any official way to do it. One very nasty way
would be to insert something like the following where you want the wrap:
<TextBlock FontSize="0.01" Margin="0,0,100000000,0"/>
but I definitely do not recommend it!!!

Chris Jobson
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Alan Mackenzie | last post: by
29 posts views Thread by runningdog | last post: by
4 posts views Thread by Peter Kirk | last post: by
5 posts views Thread by Adam Right | last post: by
1 post views Thread by linq936 | last post: by
reply views Thread by Vivien Parlat | last post: by
reply views Thread by Vivien Parlat | last post: by
reply views Thread by Chevron Boyde | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.