Reader Level:
ARTICLE

Bind ScrollBarToTextBox and TextBoxToScrollBar in Silverlight

On August 30, 2010 Articles | Silverlight with C#
Thisarticle is all about binding of scrollbar to textbox and textbox to scrollbar with small piece of code in silverlight.
  • 0
  • 0
  • 6221
Download Files:
 

This blog is all about binding of scrollbar to textbox and textbox to scrollbar with small piece of code in silverlight.

Create a new project and drag and drop a scrollbar and a textbox on page. Let's start with ScrollBarToTextBox first.

<ScrollBar Height="138" HorizontalAlignment="Left" Margin="66,10,0,0" Maximum="100" LargeChange="10" Value="{Binding ElementName=textBox1, Path=Text}" Name="scrollBar1" VerticalAlignment="Top" Width="22" />
 
<TextBox Height="23" HorizontalAlignment="Left" Margin="101,48,0,0" Name="textBox1" VerticalAlignment="Top" Width="265" Text="50" />

Here scrollbar will move according to textbox text. like if i enter 50 in textbox then scroll bar should be like this:

Image1.jpg

Image1.

If I change TextBox value then result should be like this:

Image2.jpg

Image2.

Now TextBoxToScrollBar.

<Separator Height="3" HorizontalAlignment="Left" Margin="9,154,0,0" Name="separator1" VerticalAlignment="Top" Width="471" />
<
ScrollBar Height="100" HorizontalAlignment="Left" Margin="67,175,0,0" Name="scrollBar2" VerticalAlignment="Top" Width="18" Maximum="100" LargeChange="10" />

<TextBox Height="23" HorizontalAlignment="Left" Margin="105,179,0,0" Name="textBox2" VerticalAlignment="Top" Width="261" DataContext="{Binding ElementName=scrollBar2}" Text="{Binding Path=Value}" />

And compile the application.

Image3.jpg

Image3.

When you move scroll bar the textbox text should change.

Image4.jpg

Image4.
 

Raj Kumar Beniwal

Raj Kumar Beniwal is two times Microsoft MVP(Client App Dev) and four times C# Corner MVP,  working as asst project manager with lots of hands on experience using ASP.NET 2.0/3.5, AJAX, MVC, C#, ...

  • 17rank
  • 7M readers
  • 2times
COMMENT USING

Trending up