Silverlight - How to navigate from a User Control to a normal page?

前端 未结 8 1244
南旧
南旧 2020-12-09 18:13

If I do this inside a User Control:

NavigationService.Navigate(new Uri(\"/Alliance.xaml\", UriKind.Relative));

it says this error:

8条回答
  •  长情又很酷
    2020-12-09 18:38

    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.

    1. 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.

    2. You can either allow your page access to its parent or pass the NavigationService from the page to the usercontrol.

    3. You can also set this up using messaging, but that would be more complicated.Many MVVM frameworks have messaging features. MVVM Light has it.

提交回复
热议问题