Siddharth Thevaril
Siddharth Thevaril

Reputation: 3788

How to access objects between two xaml pages in wp7?

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));
            }
        }
    }
}

Upvotes: 1

Views: 540

Answers (2)

Claus J&#248;rgensen
Claus J&#248;rgensen

Reputation: 26344

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

Upvotes: 1

Random Dev
Random Dev

Reputation: 52280

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.

Upvotes: 1

Related Questions