Windows Store Frame Navigation: How to get the source page? - c#

On windows store apps we usually use something like this:
this.Frame.Navigate( typeof(ItemDetailPage), itemId);
To navigate between the app's different pages.
After the page I want to navigate to is open, how can I know it's navigation source? How can I get the previous page type?

You are going to want to create a navigated event
void NavigationService_Navigated(object sender, NavigationEventArgs e)
{
//Your code here
}
(per http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationservice.navigated.aspx)
Then once you have this event you can look at the NavigationEventArgs
This will allow you to access the Navigator that called the event.
From THERE you should be able to grab the Navigator's Uri

Related

Invoking a method from the parent page after user control has been loaded?

May I know if there is any way to invoke a method from the child page(.aspx) after the page load of the user control is finished?
Right now I have an issue of being unable to retrieve the value from the child page because the variables from the user control has not been assigned the value yet.
To put it simply
FROM MY .ASPX FILE
Page_Load(object sender, EventArgs e)
{
x = getValueFromUserControl();
}
FROM MY USER CONTROL
Page_Load(object sender, EventArgs e)
{
int x = getvalueFromDatabase();
}
getValueFromuserControl()
{
return x;
}
Since the ASP.NET Life Cycle goes from the child page(.aspx) page_load -> user control page_load, I am unable to retrieve the value of x.
That said, ideally I would not like to put the function in the child page and call it from the user control as the user control is being used in other pages.
In short, I would like to invoke a method from my .aspx page after the page_load in my user control ends, Thank you!
Get the value at a later page event:
protected override void OnLoadComplete(EventArgs e) {
x = getValueFromUserControl();
}
Unless, of course, there is a specific reason why you must get the value on Page_Load. There are other, probably more appropriate ways to handle this, but without knowing what x is and what you need to do with it, it is hard to give any other advice. For example, maybe the UserControl should fire an event that is handled by the page.

how to prevent going back to previous page

For a windows phone 8 app I'm developing, I had to load some data at the starting of the app. For that matter I designed a page called SplashScreen.xaml that loads the data and after all the loading is done I navigate to the MainPage.xaml using:
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
Now when the user is in the main page and taps the back button on the phone instead of going out of the app(which is the default gesture) goes back to the SplashScreen.xaml, making them unable to go out of the app(except for taping the start button which take's the app to background) and of course giving them a bad impression.
The question is How to prevent going back to the previous page
Thank you all.
Just clear the backstack when landing on MainPage:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
while (NavigationService.RemoveBackEntry() != null);
}

How can I access to e.handled for a button in silverlight?

I have some buttons in master page (mainpage) and I use the event click of its in other page by map like:
MainPage mp = (MainPage)(((BusinessApplication8.Controls.BusyIndicator)Application.Current.RootVisual).Content);
it's being run more than one and I can not use a e.Handdled to prevent them.
How can I do to control it?
for example we want our code inside below event(ListPish_Emza_Click) runs only once per click :
void ListPish_Emza_Click(object sender, RoutedEventArgs e)
{
if (sender == e.OriginalSource)
return;
Approve_Click(sender, e);
}
but above code runs more than one per click.
Firing an event manually is not recommended approach.
I can't realize your application architecture. But, you should put your code in a method in static class and use it.

windows phone navigation immediately after loading page

I have 2 pages.(MainPage.xaml,second.xaml)
MainPage.xaml is the Login page. In this page I send login and password, and receive result. I save them(result) in Isolate Storage and navigate to the second.xaml page;
When i start this application in the next time, i extract data from Isolate Storage and I want to navigate the second.xaml immidiately, but i don't know how
I try write
public MainPage()
{
InitializeComponent();
//function for Isolate storage
InitializeSettings();
NavigationService.Navigate(new Uri("/Conversation.xaml", UriKind.Relative));
}
But it isn't work)
I understood that I could not use the navigation code associated with the MainPage() constructor. Of course, i may will do simple button, but i wish fast navigation
I think may be it connected with App.xaml method
private void Application_Launching(object sender, LaunchingEventArgs e)
for example, write my method
//function for Isolate storage
InitializeSettings();
with navigation there?(navigation not work in this example)
private void Application_Launching(object sender, LaunchingEventArgs e)
{
InitializeSettings();
NavigationService.Navigate(new Uri("/Conversation.xaml", UriKind.Relative));
}
Where I can use navigation, so go straight to the second.xaml page, without fully loading the MainPage.xaml(may be without MainPage.xaml)
You can do as Rana Tallal said.
Or you can write it in code:
public MainPage()
{
InitializeComponent();
Loaded += (s, e) =>
{
InitializeSettings();
// Some login-password check condition
if (_login && _password)
NavigationService.Navigate(new Uri("/Conversation.xaml",
UriKind.Relative));
}
}
Well create a new function... and in that perform the checks at which you want it to be navigated and if the checks are ok right in it than call the navigation service navigationservice.navigate(....) code.
Now you need to tell the program to call this function when the mainpage is completely loaded. To do so in the xml of mainpage inside tags at the end of it write loaded="function_name"
Now when ever the page will be loaded this function will be called. If the login information is present in the isolated storage than the navigation sevices will be called otherwise the mainpage will be shown.
Make sure to put (object sender, RoutedEventArgs e) in the functions parameters(as it is a event handler).

Click to new window.xaml

im learning wpf for the first time,
i have made this far
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
// TODO: Add event handler implementation here.
}
lets say its my click button 'home' some how i have made a new window store.xaml at the same product.
how can i connect them ?
heres a sc
Your question seems a bit vague to me, if you simply want to display the store inside the same window you should not implement the content of the window directly but only use the window as a shell for your content, if your store is a window as well you should refactor it into a UserControl which then can be added to the window.
You can also use Pages, see the Navigation Overview for more info on that.

Categories