Reputation: 5612
My XAML:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Slider Name="sldLength" Margin="0 0 0 0" Grid.Column="0"
Minimum="5" Maximum="30" SmallChange="1" LargeChange="1"
Value="10" ValueChanged="sldLength_ValueChanged"/>
<TextBlock Name="tblLength" Margin="0 10 5 0" Text="10" Grid.Column="1"
FontSize="{StaticResource PhoneFontSizeMediumLarge}"/>
</Grid>
My Code begind:
private void sldLength_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
tblLength.Text = e.NewValue.ToString();
}
2 problems:
Thnks for any help...
--EDIT--
Solved problem 1 with Chepene suggestion.
Solved problem 2 with little cheeky event handler:
private void sldLength_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
((Slider)sender).Value = Math.Round(((Slider)sender).Value);
}
Upvotes: 0
Views: 1625
Reputation: 31
This worked perfectly for me. First check the Slider's OldValue, either it null or not.
private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if(slider.OldValue != null)
{
textbox1.Text = silder1.Value.ToString();
}
}
hope this help.
Upvotes: 0
Reputation: 1128
You can use Bindings. Smth like this:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Slider Name="sldLength" Margin="0 0 0 0" Grid.Column="0"
Minimum="5" Maximum="30" SmallChange="1" LargeChange="1"
Value="10"/>
<TextBlock Name="tblLength" Margin="0 10 5 0" Text="{Binding ElemantName=sldLength, Path=Value}" Grid.Column="1"
FontSize="{StaticResource PhoneFontSizeMediumLarge}"/>
</Grid>
Here tblLength takes its text from the value of sldLength.
Upvotes: 1