Search code examples
c#wpfwindows-phone-8nulltextblock

_thetextblock.Text is null on slider minimum set as 5 not 0?


I have databinding setup on a slider and the databinding sets the slider to 5. I also set the minimum slider value as 5 using the properties in the xaml, yet it fails to compile and highlights _masterSpeedTxt.Text = line as the problem. If I hover over the _masterSpeedTxt.Text it pops up null and if I press the + and again on static members everything returns null. Yet if I set the slider at minimum 0 again it all works fine.

I'm new to programming and to me this makes no sense what so ever could it be a bug in VS Express 2012?

I've seen this but thats databinded to the slider value yet I want to convert into a percentage...

Problems with WP8 Slider

private void _masterSpeedSlider_ValueChanged(object sender,   RoutedPropertyChangedEventArgs<double> e)
    {
        double slVal = Math.Round(((Slider)sender).Value);
        //int total = 255;
        double percentage = (slVal * 500) / 250;

        _masterSpeedTxt.Text = String.Format("{0}%", Convert.ToString(percentage));

        string sendMI = Convert.ToString(Math.Round(((Slider)sender).Value));

        sendMI.PadLeft(3, '0');

        string fsSend = sendMI.PadLeft(3, '0');
        SocketConnect.sendtoFS(String.Format("FSOC206{0}", fsSend));
    }

Solution

  • adding it to :

           // Constructor
        public MainPage()
        {
            InitializeComponent();
            _masterSpeedSlider.Minimum = 5;
        }
    

    Solved the problem!