Set slider maximum programatically, c#

  • Thread starter Thread starter tree28
  • Start date Start date
T

tree28

Guest
Hello,

I'm new to c# (and wpf) and I have a very simple question.

I am trying to set the maximum value of a slider in c# as opposed to doing so in XAML. As a test I wrote a very simple function that will set an initial maximum value and then reset the value after some data is read in c# (new data is returned from a database query).

The simple test function is triggered (only as a test) when data is returned. I have discovered that the function will successfully set the initial slider value but when triggered a second time (by the query return - causing the maximum value to change), the update causes the WPF application to crash.

What am I doing wrong?


// // //

private Int32 temp_cache = 0;

private void updateMySliderMax()
{
Int32 some_slider_max = 40;
Int32 a_reduced_test_value = 4;

if (temp_cache != some_slider_max)
{
My_Slider.Value = 20;
My_Slider.Maximum = some_slider_max;
temp_cache = some_slider_max;
}
else
{
My_Slider.Value = 2;
My_Slider.Maximum = a_reduced_test_value;
}
}

Continue reading...
 
Back
Top