简体   繁体   English

导航时如何重新加载页面

[英]How to reload page when navigating

I am developing WPF MUI application.I navigate to another page using button onclick and print some text on page1.xaml . 我正在开发WPF MUI应用程序。我使用onclick按钮导航到另一页,并在page1.xaml上打印一些文本。 after i navigate using another button to print another text on page1.xaml .but i could not do that.my out put was not new text.it is early details only.can't reload page1.xaml .when navigating I pass the parameter and according to parameter print deference text on same page.can anyone help me? 在我使用另一个按钮导航以在page1.xaml上打印另一个文本后,但是我无法做到这一点。我的输出不是新文本。仅是早期详细信息。无法重新加载page1.xaml。导航时我传递参数并根据同一页上的参数打印参考文本。有人可以帮助我吗?

this is my navigation code 这是我的导航代码

var frame = NavigationHelper.FindFrame(null, this);
frame.Source = new Uri("../Content/Sale/SaleInvoice/Nested/saleNested.xaml", UriKind.Relative);

Have the page databound to a ViewModel. 使页面数据绑定到ViewModel。 Once you want to refresh just create a new Viewmodel. 一旦要刷新,只需创建一个新的Viewmodel。 It would make sense to have the execution of the reloading being done in a backgroudworker so your UI stays responsive. 在backgroudworker中执行重新加载会很有意义,这样您的UI才能保持响应状态。 This is esspecially usefull if you are refreshing some resource from a webService or some other online source. 如果您要从WebService或其他在线资源中刷新某些资源,这特别有用。

The Data bind to the page at the initial time to reload the page I'm using this method 数据在初始时间绑定到页面以重新加载我正在使用此方法的页面
On xaml page just add Loaded Property: 在xaml页面上,只需添加Loaded属性:

<UserControl x:Class="ModernUINavigationApp1.Pages.Page"
         ...
         Loaded="OnLoad" >

Then Add event handler in code behind to make the page do whatever you want when it's loaded 然后在后面的代码中添加事件处理程序,以使页面在加载时可以执行所需的操作

private void OnLoad(object sender, RoutedEventArgs e)
    {

    }

Hope this help :D 希望这个帮助:D

Make sure your ViewModel implements INotifyPropertyChanged . 确保您的ViewModel实现了INotifyPropertyChanged If your Page1.xaml's DataContext is set to the ViewModel, and your XAML uses bindings properly, any change to the ViewModel will be reflected in the UI. 如果将Page1.xaml的DataContext设置为ViewModel,并且XAML正确使用了绑定,则对ViewModel所做的任何更改都将反映在UI中。 You won't need to refresh anything. 您无需刷新任何内容。 Just update the property in the ViewModel object. 只需更新ViewModel对象中的属性即可。

If you update your question with example XAML and C#, I can be of more help. 如果您使用示例XAML和C#更新问题,那么我将为您提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM