Wednesday, April 9, 2008

Multiline TextBox in Silverlight 2.0

Its set of workarounds only.There is no support in silverlight 2.0 to have a multiline textbox.But we should accomplish as we might be in deadline :-).It leads to workarounds.
What I did ,was to set AcceptsReturn property of TextBox.Now it will accept Returns ie EnterKey and create one more line by increasing its' Height.
Now the next problem came.ScrollBars..
I tried setting ScrollViewer.VerticalScrollBarVisibility="Visible".But it gave me runtime error.(Dont know why VS2008 showed intellisense to add ScrollViewer.VerticalScrollBarVisibility="Visible").
Again workaround.Put this TextBox in a ScrollViewer.
Finally it looks like




<ScrollViewer Height="100" Width="100" HorizontalScrollBarVisibility="Visible">

<TextBox Text="Javascripting Silverlight 2.0"

AcceptsReturn="True"

/>

ScrollViewer>



Sample located here

4 comments:

WebMasterSam said...

Instead of emulating a scrollable textbox, you can use the built-in features of the textbox and use it like this :

<TextBox
VerticalScrollBarVisibility=”Visible”
HorizontalScrollBarVisibility=”Auto”
AcceptsReturn=”True” />

Joymon said...

Thats a good idea :-)

Anonymous said...

You should add Wrap so that you have multiple lines as below...

Anonymous said...

For Multiple Lines in Text Box following code is fine if it is a TextBlock then you need to have ScrollViewer to acive this...