Navigation between pages in WP8.1 - c#

I'm trying to migrate my app from WP8 to WP8.1. And I don't get how to navigate to already opened page with another parameters.
For example, I'm showing user info on UserPage giving it user's id as parameter. And when page is already is the content of the Frame I want to open UserPage again but for other user giving it another id.
My problem is that, using NavigationCacheMode set to Required for UserPage means that there will be no navigation with other parameters. But when NavigationCacheMode is set to Disabled navigation with another parameter is success but when I press back button old instance of UserPage is using data from new one.
In WP8 passing new parameters was enough to create new instance of a page with it's own cache. How to do similar in WP8.1 using WRT APIs?

Thanks to Romansz for the tip about using UserControl. Using UserControl binding to a ContentControl and handling BackKeyPress solves my problem with navigation.

Related

.NET MAUI: Switching the App's MainPage multiple times leads to exception

The root of a .NET MAUI application is the class App : Application.
This class has a property Page? MainPage that contains the current root page.
I try to use this property for navigation. I wrote a method App.ShowPage(Page page) that sets the property MainPage to the given page.
This works like a charm! I start my application and show a login page - works.
When the user clicks login on my login page I show the main view (a TabbedPage) - works.
When the user clicks on an item on that main view a details view gets shown - works.
Now when the user clicks cancel on that detail view, I try to navigate back to the main view. As always with my method App.ShowPage(Page page). Now I get an exception:
IllegalStateException; The specified child already has a parent. You
must call removeView() on the child's parent first.
So the error message tries to tell me what to do. And I do find properties like Element Parent or Element RealParent on the Page page I try to open - but they are all null. So how do I remove the page from that parent? What is the removeView() method in the .NET MAUI world?
Thanks in advance for any help!

How to reload or refresh a Windowsphone User Control in c#?

I am making a windowsphone silverlight App for windowsphone OS 8. I am Using windowsphone user controls where I make changes dynamically.
My question is just like the way we create an instance of a phoneApplication Page for Normal .xaml Page using NavigationService.Navigate("Source Uri with unique GUID") . How can I achieve the same effect for a windowsphone User Control Page where I make my dynamic changes to update as there is no Navigation Service.Navigate() method available. ?
Currently I have to Navigate like UserControl-Page-UserControl
When you want to Navigate from a page, you can use NavigationService.Navigate().
When you want to Navigate from a UserControl, You can use the PhoneApplicationFrame to navigate.
Code Sample:
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MyProjectName;component/MyFolderName/MyPage.xaml", UriKind.Relative));
You need to append a GUID when you want to navigate to a new instance of the same page which you are currently residing.

Use text box in another page to edit code of a button?

I'm creating a web browser. On the "mainpage" it has a button that takes you to the homepage, i'd like to give the user the option of changing the home page on "page1" (settings). on page1 I have "textBox1"(where the user enter desired homepage) and "button1" (set). Could you help me set this up? Is there a way where doing that action can change the source of webBrowser1?
First I would suggest you to download this Programming Windows Phone 7 ebook and explore it to learn Windows phone programming before asking StackOverflow.
Coming to your question,
Create a Settings class in the project and Add a static string property named something like "HomePageUri". Then in your Page1, add the source uri to that "HomePageUri".
Then in your main page, in the OnNavigatedTo event update the WebBrowser's source or you can bind the WebBrowser's source directly to the "HomePageUri" property
Good luck

How to Target the current frame in Silverlight using C#?

If I have a button in a navigation page, how do I make it target the frame that it is in?
For example, I have a frame called navFrame in MainPage.xaml and I have a navigation page in the Views folder called Home.xaml with a button on it. Basically I'm trying to make clicking the button Home.xaml target the navFrame in MainPage.xaml.
Is that possible? for the button code I tried using MainPage.navFrame.Navigate(...) but it gave me the error "an object is required to reference a non static property..." but I don't know what kind of object it wants or how I would use it.
I'm sorry if this is a stupid question. I'm new to all of this and I spent all last night trying to figure out. Any help would be really appreciated!
From the error message it seems that you don't have a reference to the instance of MainPage in the Home class.
You could get a reference to it through searching up the Visual Tree or calling Application.Current.RootVisual or using some kind of locator framework.
But you don't really need to get a reference to MainPage. From inside the Home : Page class you could instead try
this.NavigationService.Navigate(new Uri("/About", UriKind.Relative))

Can't find the function body in ASP.NET

I recently started working on a project that has been in development for some time now. The problem is this - in the web site page, a have a frame (amongst 4 others) in a frameset which contains the SVG map object (the whole site is GIS based). Also, in the same frame, there is a icon for opening the form in which user can choose a number of filters, and after he presses a button, the map refreshes and the area of influence around some key points on the map are drawn.
What i need to do is to open that form in a new (popup) window and not in the same frame where the map is. I did that this way:
onclick="window.open('zi.aspx','form1','width=700,height=500,left=350,top=100')"
This works fine. But then, when i enter the filters and hit Generate button, i get this error:
'parent.frames.map' is null or not an object
with the reference to zi.aspx. Now i know that this error is because i changed the form from opening in the same frame as map to opening it in a popup window, but i just can't find anywhere in the code where can i modify it. Before my changes, the code was just this:
onclick="showZi();"
and that is the function i can't find anywhere. Any ideas? How can i make this work, to make a map with filters drawn after the user has chosen appropriate ones from the popup window form? I should mention that this image link is in the ASP.NET table, with standard runat="server" command.
Okay, so you're opening a new window from javascript. Your problem is that you're trying to access the parent window by using the 'window.parent' property. This is wrong, you'll need to instead use 'window.opener' property. E.g.:
window.opener.frames.map

Categories