Modern UI for WPF- navigation

喜你入骨 提交于 2019-12-20 07:12:27

问题


How can I pass parameter beetwen pages? I've tried to add parameters to page uri but it didn't work because I can't use onNavigatedTo event on user control. Please help


回答1:


You must use OnFragmentNavigation.

public void OnFragmentNavigation(FragmentNavigationEventArgs e)
{
  DoYourStuff(e.Fragment)
}

e.Fragement contains everything past the # in the URI. In example, using

NavigationCommands.GoToPage.Execute("/Pages/CustomerPage.xaml#CustomerID=12345", this);

e.Fragment will be "CustomerID=12345"




回答2:


It looks like you are coming from a client browser showing web pages world. With WPF you own the app! you can simply set the value on the new page before or after navigating, pass it in with a constructor or access it from a location accessible from both pages. It sounds like the parameter is an argument to the page so I would pass it in with a constructor in this case:

public class APage : Page
{
    private object myVar; // use whatever Type you want

    public APage
    {
        InitializeComponent();
    }

    public APage(object arg) : this()
    { 
        this.myVar = args;
    }
}


来源:https://stackoverflow.com/questions/20316996/modern-ui-for-wpf-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!