I load a page in my app, the user does some modifications on it. By the push of a button on that certain page, I want to reset the page to its initial form. I've tried NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.RelativeOrAbsolute)); but it doesn't work, since the From and To pages are the same. Also, I have thought of putting a new page in between, but it sounds bad. Also, it would be best if I didn't have to screw the Navigation History (i.e. the back button) by navigating without reason to another page. So any solution for a page reset? Thanks.
I found the right answer. In order to reset the page to its initial form you have to do this:
void buttonResetPage_Click(object sender, RoutedEventArgs e)
{
this._contentLoaded = false;
InitializeComponent();
// other initializations found in your page constructor
}
It worked for me. :)
I did it in the following way:
ContentFrame.Content = New {pagename}
this sets the contentFrame, which contains my webpages page1,page2 etc, to a brand new instance of that page. This then reloads everything on that page, the layout and also gets the data back from the database again. This way worked for me.
Related
I have two buttons in My View. One is Download Book and other is View Book. When i click on the View button I navigate to other page and Save the DataPager Current page. and on navigating back i have to show the Previously saved page in DataPager.
Is there any Method or property which i can use to Jump to Selected Page in DataPager Control in Silverlight 5.
I have get the Current Page number using the PageIndex but could not find a way to Navigate back to the same page. Every time The Page is starting From 1 and PageIndex 0.
Any help will be Appreciated. Thanx in advance.
Just make an event like
((BooksViewModel)LayoutRoot.DataContext).PropertyChanged += new PropertyChangedEventHandler(BooksView_PropertyChanged);
and call the
void BooksView_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "AnyDistinguishedstring")
{
Pager.PageIndex = 4; //it will take you to the page 5
}
}
and From Viewmodel call the
NotifyPropertyChanged("AnyDistinguishedstring");
will do the trick. :)
I'm working on a Windows Phone 7 Silverlight application. I was wondering if there is a case where the OnNavigatedTo() function is not called when using NavigationService.GoBack() ?
I'm working with two pages, one can add items to a database and the other can edit items in the database. The main page sends the user to each page with
NavigationService.Navigate(new Uri(string.Format("/views/Add.xaml?parameter={0}", parameter), UriKind.Relative));
NavigationService.Navigate(new Uri(string.Format("/views/Edit.xaml?parameter1={0}¶meter2={1}", param1, param2), UriKind.Relative));
Both options bring the user to a new page and both return the user via
NavigationService.GoBack()
I have my OnNavigatedTo() function declared in MainPage, however only the Add page causes the function to execute while the Edit page seems to skip it on the return. The OnNavigatedTo() function repopulates an ObservableCollection to reflect the changes made by the user.
No, the OnNavigatedTo() will definitely be called. You can verify that using breakpoints while debugging. I think the problem might be the way you update your Collection. Some more code might help.
I'm using a PasswordBox on a Page. Because of the implemented workflow the user can navigate to sub pages (NavigationWindow) and than return with GoBack() to the main page.
But when doing that, the password box is always empty! My job is to prevent that behaviour, but at the moment I have no clue how do achive that.
It would be great if you could help me out.
Thanks
It is a feature.
See: How to bind to a PasswordBox in MVVM
To enable the backward navigation the state of the page needs to be stored. And that is not secure.
I don't think his exact problem is a feature, but a bug of the navigation service.
In your code behind you have no easy way to distinguish between the navigation control blanking your password on navigation or the user blanking it by deleting it from the box.
So if you don't consider that, your password in your viewmodel will always be blank if you navigate to another page.
I used this hack to determine who called my password changed handler to update the view model:
private void PasswordBox_OnPasswordChanged(object sender, RoutedEventArgs e)
{
StackTrace stack = new StackTrace();
StackFrame[] stackframes = stack.GetFrames();
foreach (StackFrame stackFrame in stackframes)
if(stackFrame.GetMethod().Name == "Navigate")
return;
ViewModelPassword = PasswordBox.SecurePassword;
....
Take a look here too: http://www.wpfsharp.com/2011/04/08/wpf-navigationservice-blanks-passwordbox-password-which-breaks-the-mvvm-passwordhelper/
In Microsoft's Toolkit DataForm
User is trying to add a new item in Toolkit Dataform by clicking Add icon. In the middle if he selects any other menu tab, then he is going to lose all the entered info.
I want to show promt to User to Save When Leaving a Page. Like Warning user before leaving page with unsaved changes.
After some research I found the solution.
Theere is a Method called OnNavigatingFrom in Silverlight page. that methods is Called just before a page is no longer the active page in a frame.
So you can add any alert or confirm message in that methods.
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (DataForm.IsEditMode)
{
System.Windows.Browser.HtmlPage.Window.Alert("Please Save or Cancel changes before switching the page");
e.Cancel = true;
}
base.OnNavigatingFrom(e);
}
that will be called when you want to move to other page from current page edit or add mode.
I have a WPF System.Windows.Controls.WebBrowser control in a Window. A user can enter information and hit a submit button into the webpage displayed by the WebBrowser. After the page posts back it uses a scripting object to communicate with my application. I need to make sure that once the submit button has been pressed, the form doesn't close or otherwise stop waiting for the web page to post back. It would be great if I could check the state of the WebBrowser or its document via a property like "IsLoading" and cancel any actions if it is loading. I didn't see anything like that so I was thinking of setting a flag on the Navigating event and unsetting it on the Navigated or LoadCompleted event, but there is a case where I click a link on the web page (tied to javascript, it doesn't go to a new page) where Navigating is fired, but Navigated and LoadCompleted never fire. Is there a way to determine the state of the browser on demand?
As per MSDN if the Navigating event gets invoked then the Navigated Event will also get fired unless you explicitly Cancel the navigation. I tried the below code-snippet it seems to be working fine. (i.e) whenever the Navigated event is getting fired following Navigating event.
void Window1_Loaded(object sender, RoutedEventArgs e)
{
browser = new WebBrowser();
browser.Navigate(new Uri("http://www.google.com"));
browser.Navigating += new NavigatingCancelEventHandler(browser_Navigating);
browser.Navigated += new NavigatedEventHandler(browser_Navigated);
}
void browser_Navigating(object sender, NavigatingCancelEventArgs e)
{
Console.WriteLine("Loading Webpage !!");
}
void browser_Navigated(object sender, NavigationEventArgs e)
{
Console.WriteLine("Webpage Loaded !!");
}
If this is not what you are looking for, then provide the webpage URL in which you are facing the issue.
No, there does not appear to be a way to query the WPF browser's status on demand. I settled on my original idea of setting my own flag in the Navigating event handler and unsetting it in the Navigated event handler. It was not working reliably for me because there was a script that canceled navigation (javascript:void(0)).