0

SOLVED

Actually, I solved the problem by removing the "Value_Changed" event from the XAML and adding it manually with C# AFTER setting the value of the slider. Otherwise it looks like the slider take the minimum value possible - Thanks to all

I have two page, one page have a slider which have to takes the value of a variable from the first page.

Main.xaml.cs

public static int val;
...//Some stuff here

val = Converti.ToInt32(roamingSetting.Value["Setting"]);
...//Some stuff there

Then the second page

Second.xaml.cs

public Settings()
{
    this.InitializeComponent();
    slider.Value = Main.val;    //looks like this line does not do his job  
}
private void slider_ValueChanged(object s, RangeBaseValueChangedEventArgs e)
{
    writeToRoaming(slider.Value.Tostring());
}

Slider XAML

<Slider x:Name="slider" Minimum="5" Maximum="100" IsThumbToolTipEnabled="True" ValueChanged="slider_ValueChanged"/>

The fact is that the value of the slider is never set to the value of the setting

Community
  • 1
  • 1
Sven Borden
  • 1,070
  • 1
  • 13
  • 29

2 Answers2

0

It might be some issue with biding of slider with your val variable. But we you can get the new value from events args in slide value change event. It will write the latest values into the roaming settings and fix the problem.

private void slider_ValueChanged(object s, RangeBaseValueChangedEventArgs e)
{
    writeToRoaming(e.NewValue.ToString());
}
Haseeb Asif
  • 1,766
  • 2
  • 23
  • 41
0

I've recreated your scenario and it works for me but think you could be seeing one of the following:

  • there is no roaming settings value
  • the roaming settings value that is being used is outside the maximum and minimum values that you've defined for the slider
Matt Lacey
  • 65,560
  • 11
  • 91
  • 143