Refresh current page in wp8, - c#

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.

just enter your desired page there on any event you wish it will refresh the page
NavigationService.Navigate(new Uri("/pagetorefresh.xaml", UriKind.Relative));

Did you try removing the BackStack?
NavigationService.RemoveBackEntry();
How to reload a Windows phone application page without creating a new copy in the memory?
navigating to same page in windows phone 8

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

Related

Immediately redirect to another page in WPF

I have a page that several other pages navigate to. However in some circumstances the user should not see this page, so I want to send them to another page instead.
Rather than update the rest of the calling code, I just want to change this page to handle it.
public MyPage()
{
Loaded += MyPage_Loaded;
InitializeComponent();
// Other stuff
}
void MyPage_Loaded(object sender, RoutedEventArgs e)
{
if(condition)
NavigationService.Navigate(someUri);
}
Since the NavigationService isn't available in the constructor I have to hook up to the Loaded event and do the redirect there. The problem is that the page has already been loaded and displayed to the user. There is also a slight delay before redirecting the user.
Is there a better way to do this where the redirect is seamless?

Telerik PageViewPage on PageRemoved for winforms

I am currently facing a problem which i cannot find a solution to.
I´m using Telerik RadPageView to manage different views. When i close a page (PageViewPage) i wish to execute some code regrading the view inserted into the page. I have tried to use the FormClosed() event on the view, but it is not fired.
Then i decided to try using the PageView event (PageRemoved()) for closing a page, but i cannot find the View object i need to access using the sender.
So now i´m praying someone out there can help my out of my misery ;)
Thanks in advance!
FormClosed event is only fired if you close your whole form, not only a RadPageViewPage. I guess you're on the right way with PageRemoved event. In this event, your sender object is your RadPageView. To get the current page which was removed, use the RadPageViewEventArgs from your event.
private void radPageView1_PageRemoved(object sender, RadPageViewEventArgs e)
{
MessageBox.Show(e.Page.Text);
}
To get your sender as a RadPageView, have a look at this.
RadPageView view = (RadPageView)sender;
or
RadPageView view = sender as RadPageView;

how to access a user define controls iner controls in parent form

I'm new to windows forms programming so my question may sound little strange.
I have created a user define control (countdown timer) now I'm creating n no of it dynamically in a form by Click of a button (Add new timer) its working well and good.
Here is the Creation Code
private void Addnew_Click(object sender, EventArgs e)
{
UserControl1.userControl11 = new UserControl1();
flowLayoutPanel1.Controls.Add(userControl11);
}
My user control has a Reset button that reset all the content inside the user define control.
it is also working, but What I want Allow user to reset all the Created timers using the “Reset All” button on the form.
Okay one way to do this.
Create a List<UserControl1> private member on your form called say _myUserControls
In your Addnew Handler add it to the list.
If you have a remove button, don't forget to remove from _myUserControls as well.
Add a Reset method to your UserControl1, that does what it needs to do.
Then in your Reset all button click handler
foreach(UserControl1 ctrl in _myUserControls)
{
ctrl.Reset();
}
Jobs a good 'un
The answer I referred you to in comments, would be a way of finding all instances of your UserControl1 class, so you wouldn't need an internal list.

Adding controls to tab page runtime

I am using C# and winForms, I have a few tabcontrols, which contains a few tab pages,
I would like to add all tab pages my user control, it would be best, If I could add it after user click on tab page. It works for me only, when I add this controls in constructor - what makes delay at application start - about 3 seconds, what is very much.
I would like to add this controls at run time, like
tabPage1.onClickEvent()
{
tabPage1.Controls.Add(myUserControl);
}
but it didnt works, I also tryied to use Invalidate, or Refresh method but it not works.
So is there any possibility to add this userControls in other method than constructor?
Maybe its problem, that I have TabControl inside TabControl and I have to add this controls throught parent TabControl?
Thanks!
Try double clicking the tag page in the designer, or you can add the event handler manually like this:
tabPage1.Click += new EventHandler(tagPage1_Click);
I don't know whether tabPage1 is dynamic, but if it's not, you should add the above event handler to your designer.cs file.
Here is the event handler in the code:
protected void tabPage1_Click(object sender, EventArgs e)
{
tagPage1.Controls.Add(new TextBox());
}

C#, Windows Phone 7, Using if-else statement to check which page is displayed

Now I'm developing a Windows Phone 7 app, my app has three buttons located at the applicaton bar. Here is the event handler for these three buttons:
//app bar page navigation
private void ApplicationBarIconButton_Click1(object sender, EventArgs e)
{
if(//check if the current displayed page is mainpage)
{
//do nothing
}
else
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
}
}
private void ApplicationBarIconButton_Click2(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Audios.xaml", UriKind.RelativeOrAbsolute));
}
private void ApplicationBarIconButton_Click3(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Statistics.xaml", UriKind.RelativeOrAbsolute));
}
The button navigation works well except the first one (Button_Click1) because when I first access the main page and click the first button the app will automatically go back to app list.
So I want to use if-else statement to check which page is currently displayed and then decide whether to navigate or stay in the current page.
It looks like you are using the ApplicationBar like you would use a TabBar within iPhone (or similar in Android, Bada, etc too)
In WP7, the Metro style is typpically to use a Pivot or Panorama rather than a "Tab Bar" for this type of navigation.
If you do want to use the ApplicationBar like this:
then you can (the WP7 Marketplace will allow it) but users might feel it's not very Metro.
then you might want to consider disabling the appropriate button rather than just stubbing out the action.
then you can detect the currently shown page using CurrentSource on the NavigationService
Also, please do note that if you try to navigate from MainPage.xaml to the same url MainPage.xaml then you will see an exception - as I recall, the navigation service complains about url fragments not being supported.
Button click1 should be removed from the main page. It makes no sense to have that button there.
Other pages should use the back button to return to the main page. Otherwise you mess up your back stack.

Categories

Resources