If I do this inside a User Control:
NavigationService.Navigate(new Uri("/Alliance.xaml", UriKind.Relative));
it says this error:
An object reference is required for the non-static field, method, or property 'System.Windows.Navigation.NavigationService.Navigate(System.Uri)'
Thank you
Well, I solved passing the normal Page as an argument to the User Control, so I could get the NavigationService.
NavigationService is a property of the page object in Silverlight, which is why you are getting this error. It is not a property of a UserControl in Silverlight.
The following are a few options which will be able to solve the issue you're seeing.
Treat the usercontrol as a control. Give it an event which it will fire when the button is clicked. The page can listen for that event and handle the navigation when it fires.
You can either allow your page access to its parent or pass the NavigationService from the page to the usercontrol.
You can also set this up using messaging, but that would be more complicated.Many MVVM frameworks have messaging features. MVVM Light has it.
Here is another solution for Silverlight for Windows Phone 8:
I normally use an EventHandler. Example: in your user control, define something like
that you will call in your control foe example like this:
Then in the constructor of your MainPage.xaml.cs (if the user control is contained there) you will define:
and somewhere in your MainPage.xaml.cs you finaly declare the action to be done: