简体   繁体   中英

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 . So, in your user control create an event handler like this..

public event EventHandler Refresh;

Now, in your page make its Handle as..

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

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

 (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

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

DataBinding is the best approach and you can get notified using INotifyPropertyChanged when some changes happens with the Usercontrol. See DataBinding for Windows Phone 8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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