Bind ScrollBarToTextBox and TextBoxToScrollBar in Silverlight


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.
 

Up Next
    Ebook Download
    View all
    Learn
    View all