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

前端 未结 8 1239
南旧
南旧 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条回答
  •  猫巷女王i
    2020-12-09 18:27

    I normally use an EventHandler. Example: in your user control, define something like

    public event EventHandler goToThatPage;
    

    that you will call in your control foe example like this:

    goToThatPage(this, new EventArgs());
    

    Then in the constructor of your MainPage.xaml.cs (if the user control is contained there) you will define:

    uxControlName.goToThatPage+= new EventHandler(ControlGoToThatPage);
    

    and somewhere in your MainPage.xaml.cs you finaly declare the action to be done:

        void ControlGoToThatPage(object sender, EventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/Pages/ThatPage.xaml", UriKind.Relative));
        }
    

提交回复
热议问题