-->

Saturday, August 23, 2014

Bind the Text property of a Text Box to the value property of a Slider in windows phone

Bind the Text property of a Text Box to the value property of a Slider in windows phone

Its a very simple method to bind Text Box from slider control in the windows phone. You can use Property="{Binding <source property>, ElementName=<Source Name>}" this method. Lets take an simple example
1. Add one Silder and One Text Box control on windows phone phone.

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
           
            <TextBox x:Name="txtbox1" HorizontalAlignment="Left" Height="72" Margin="33,139,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="335" AcceptsReturn="True" Text="{Binding Value,ElementName=slider1}"></TextBox>

            <Slider x:Name="slider1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="446" Margin="0,39,0,0" ValueChanged="slider1_ValueChanged"/>

        </Grid>

Code Generate the following output

Bind the Text property of a Text Box to the value property of a Slider in windows phone
If you want to show only integer number into text box then use Round( ) method of Meth class in ValueChanged event. Add this in .xaml.cs file

 private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            slider1.Value = Math.Round(e.NewValue);
        }

Code generate the following output

Bind the Text property of a Text Box to the value property of a Slider in windows phone

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved