1

I'm working on a wp7 application which consists of two xaml pages. Pages are Page1 and Page2. Page1 consists of a slider which has a range of values between 0 to 10. My program is,if I slide the slider to reach value = 10,it should navigate to Page2. So far so good. But when Page2 is loaded,I want my slider to set its value to 0. But when I press the "back" key on my windows phone,the Page2 navigates to Page1 & the slider has the value = 10 (which should be 0). I cannot do the coding of slider from Page2 because it cannot access it! How should I do it?

The program for Page1(MainPage) is

namespace ProgressBar
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (slider1.Value == 10)
            {
                NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative));
            }
        }
    }
}
FredM
  • 454
  • 9
  • 20
Siddharth Thevaril
  • 3,722
  • 3
  • 35
  • 71

2 Answers2

1

in this case just reset the slider to 0 before navigating to your Page2 or when you navigateback (there is a event for this in the NavigationService).

To share information accross your application in the general case you can just use static-classes/fields or objects your parse around or just persit the settings/info on file. It's the same as with any other environment.

Random Dev
  • 51,810
  • 9
  • 92
  • 119
  • I tried to reset slider to 0 before navigating.What I did is outside the if() block,I set the value as slider1.value=0; but as I run the prohram,the slider doesn't move at all! now what should I do? – Siddharth Thevaril Sep 17 '11 at 13:02
  • outside the if-block? You should do this before the NavigationService.Navigate call. – Random Dev Sep 17 '11 at 13:11
  • After the Navigation call works as well. A call to Navigate isn't the equivalent of a return statement, so all code in the same tree is still executed. – Claus Jørgensen Sep 17 '11 at 13:13
1

Reset the Slider value to 0 in the Page.OnNavigatedTo event.

Claus Jørgensen
  • 25,882
  • 9
  • 87
  • 150