namespace WindowsPhoneApp
{
Class MainPage()
{
private void ProcentSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
ShowSliderValue.Text = ProcentSlider.Value.ToString(); //<-- NullReferenceException
}
}
}
我无法将Slider控件的值引用到TextBox控件...
答案 0 :(得分:1)
试试这个 - 可能是因为ShowSliderValue在不同的线程中运行..但是有点猜测。
private void ProcentSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Dispatcher.BeginInvoke(new Action(() => ShowSliderValue.Text = ProcentSlider.Value.ToString();));
}
或者也许这个?
private void ProcentSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
var slider = (ProcentSlider)sender;
ShowSliderValue.Text = slider.Value.ToString();
}