Jump to selected page using DataPager Control in Silverlight - silverlight

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. :)

Related

WPF Tab_selectionChanged

I have this strange issue I am facing currently.
I have created an WPF application based on WPF page navigation. I have few button and depending on the button click the the user is navigated to respective WPF page.
In these WPF pages I have Tab controls and have used selectionchanged event handler to perform some task.
Now to the issue,
When I try to go a particular page, the selectionchanged event is also executed even before the page is loaded completely, I have tried to use the windows.loaded (based on the answer provided to my previous question - here) - I have no luck.
[I am using WPF Navigation framework]
Somehow the selectionchanged event is executing twice.
How do I stop this from happening?
I think you should check SelectionChange.AddedItems and SelectionChange.RemovedItems to find the difference between these to firings. I guess that when you select a page, SelectionChange.RemovedItems==0 while when you click on a tabItem to select it, SelectionChange.RemovedItems==1. if so just write:
if (SelectionChange.RemovedItems==0)
return;
Edit1: Please see the first comment.
Edit 2
void tablcontrol_SelectionChange(object sender, SelectionChangedEventArgs e)
{
if (e.RemovedItems.Count == 0)
{
// I guess this is the event that happens when a page is selected
// in this case just a TabItem is added to the selection
// and nothing is removed, so do nothing
return;
}
// if you are here, it means that this is another selection changed event
// so Perform those tasks that you mentioned in your question
}

equivalent frame in windows application and navigate from page to another page?

what is equivalent "frame" in C# application?
I must navigate from page to another page in windows application. I create master page and use some panel in page. I want to navigate from every panel to another page. how do i do?
you have to create a new window in a project and create an instance and then in a code when sb will click the nav element you need to create an instance of than window class and than invoke using method showWindow()
thank for your answer. but I get find my answer!:)
in master page , should use some panel and create user control.
you design whatever you want in user control, and in button_click in master page, get instance from user control and add to panel.
this codes are:
private void button_Click(object sender, EventArgs e)
usercontol1 user=new usercontrol1();
panel.controls.clear();
panel.controls.add(user);

In Microsoft's Toolkit DataForm, Is there any feature Prompting the User to Save When Leaving a Page

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.

Reset page to initial form

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.

Determine if WPF WebBrowser is loading a page

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

Resources