简体   繁体   English

刷新wp8中的当前页面,

[英]Refresh current page in wp8,

I'm try to refresh current page but not able to do this. 我正在尝试刷新当前页面,但无法执行此操作。 Basically I used user control and inherit to another user control. 基本上,我使用了用户控件并继承了另一个用户控件。 Button click event is working properly. 按钮单击事件正常运行。 But not refresh the page. 但不刷新页面。

Page = (Application.Current.RootVisual as Frame).Content as Page;
string u = Convert.ToString(Page.NavigationService.CurrentSource);
Page.NavigationService.Navigate(new Uri(u, UriKind.Relative)); 

The Problem here is you can't use navigation in UserControl , It must be from Page . 这里的问题是您不能在UserControl使用导航,它必须来自Page So, in your user control create an event handler like this.. 因此,在用户控件中创建一个这样的事件处理程序。

public event EventHandler Refresh;

Now, in your page make its Handle as.. 现在,在页面中将其Handle为..

MyUserControl.Refresh += UserControl_Refresh;

void MyUserControl_Refresh(object sender, EventArgs e)
{
    //refresh logic here
}

Then in your UserControl invoke this Event where ever required as 然后在您的UserControl调用此Event

Refresh.Invoke(this, null);

And it will work. 它将起作用。

只要在任何需要的事件上输入您想要的页面即可刷新页面

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

When you want to Navigate to a Page from UserControl, you have to do like this 当您想从UserControl导航到页面时,您必须这样做

 (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/ProjectName;component/Pages/SignatureCapturePage.xaml", UriKind.Relative));        

And when you want to Navigate to a new instance of a page(in which you are residing), you need to append a new GUID 并且当您要导航到页面的新实例(您所在的页面)时,您需要附加一个新的GUID

(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/ProjectName;component/Pages/SignatureCapturePage.xaml?id="+Guid.NewGuid().ToString(), UriKind.Relative));        

But your ultimate purpose it to refresh the page and not to navigate to a new page, so you can either trigger a event in the page from your UserControl or go for DataBinding. 但是您的最终目的是刷新页面而不导航到新页面,因此您可以从UserControl触发页面中的事件,也可以使用DataBinding。

DataBinding is the best approach and you can get notified using INotifyPropertyChanged when some changes happens with the Usercontrol. DataBinding是最好的方法,当Usercontrol发生某些更改时,您可以使用INotifyPropertyChanged接收通知。 See DataBinding for Windows Phone 8 请参阅Windows Phone 8的数据绑定

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

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