Answered by:
navigate to a Page

Question
-
Hi,
how can I navigate to a page. I have the following code in Metro Stayle developer:
public void navigate(object navigationParam, string viewClass) { frame.Navigate(viewClass, navigationParam); }
but it doesn't work in Consumer. I have tried this:
public void navigate(object navigationParam, string viewClass) { frame.Navigate(viewClass.GetType(), navigationParam); }
I have a error message (fatal error) with this code.
Thanks
Wednesday, April 11, 2012 7:37 AM
Answers
-
Hi Lowterm,
This change is mentioned in //Build to Windows 8 Consumer Preview
In Consumer Preview, you need to "Replace any usage of String instances with these navigation APIs with: C#: Type instances".
viewClass.GetType() in your code is the type of String. You can pass the type of the page you want to navigate to instead.
Best regards,
Min Zhu [MSFT]
MSDN Community Support | Feedback to us
- Proposed as answer by Soroush Mirzaei Wednesday, April 11, 2012 9:23 AM
- Marked as answer by Min ZhuMember Thursday, April 12, 2012 1:16 AM
Wednesday, April 11, 2012 8:30 AMModerator -
As "Min Zhu" mentioned, you need to use typed instance instead of string, so you can just change your code like this:
public static Type page1 = typeof(MyProject.view.page1); public static Type page2 = typeof(MyProject.view.page2);
-Soroush
- Marked as answer by Min ZhuMember Thursday, April 12, 2012 1:17 AM
Wednesday, April 11, 2012 9:58 AM -
Hi,
Thank you very much. It works.
Thanks again
- Marked as answer by Lowterm Wednesday, April 11, 2012 10:10 AM
Wednesday, April 11, 2012 10:10 AM
All replies
-
Hi Lowterm,
This change is mentioned in //Build to Windows 8 Consumer Preview
In Consumer Preview, you need to "Replace any usage of String instances with these navigation APIs with: C#: Type instances".
viewClass.GetType() in your code is the type of String. You can pass the type of the page you want to navigate to instead.
Best regards,
Min Zhu [MSFT]
MSDN Community Support | Feedback to us
- Proposed as answer by Soroush Mirzaei Wednesday, April 11, 2012 9:23 AM
- Marked as answer by Min ZhuMember Thursday, April 12, 2012 1:16 AM
Wednesday, April 11, 2012 8:30 AMModerator -
Hi,
thanks for helping. I pass already the type of the page which I want to navigate to, but I should do this as a string.
Thanks
Wednesday, April 11, 2012 9:18 AM -
Instead of getting the type which returns a string, you should use typeof like this:
public void navigate(object navigationParam, string viewClass) { frame.Navigate(typeof(viewClass), navigationParam); }
-Soroush
Wednesday, April 11, 2012 9:23 AM -
Hi,
this is not possible:
The type or Namespace "viewClass" could not be found.
Thanks
Wednesday, April 11, 2012 9:29 AM -
I copied "viewClass" from the code that you've posted, you need to change it to name of the page that you want to navigate to.
-Soroush
Wednesday, April 11, 2012 9:32 AM -
Unfortunately I can not do this. I have several pages thet I want to navigate to. I pass the page names + namespaces as string to the navigate method like this:
public static string page1 = "MyProject.view.page1"; public static string page2 = "MyProject.view.page2"; region.navigate(null, page1); region.navigate(null, page2);
Thanks
Wednesday, April 11, 2012 9:42 AM -
As "Min Zhu" mentioned, you need to use typed instance instead of string, so you can just change your code like this:
public static Type page1 = typeof(MyProject.view.page1); public static Type page2 = typeof(MyProject.view.page2);
-Soroush
- Marked as answer by Min ZhuMember Thursday, April 12, 2012 1:17 AM
Wednesday, April 11, 2012 9:58 AM -
Hi Lowterm,
Based on my understanding, I think what the Whitepaper suggests is to also change these page1, page2 to Type.
public static Type page1 = typeof(MyProject.view.page1); public static Type page2 = typeof(MyProject.view.page2)"; region.navigate(null, page1); region.navigate(null, page2);
Best regards,Min Zhu [MSFT]
MSDN Community Support | Feedback to us
- Marked as answer by Min ZhuMember Thursday, April 12, 2012 1:17 AM
- Unmarked as answer by Min ZhuMember Thursday, April 12, 2012 1:17 AM
Wednesday, April 11, 2012 9:58 AMModerator -
Hi,
Thank you very much. It works.
Thanks again
- Marked as answer by Lowterm Wednesday, April 11, 2012 10:10 AM
Wednesday, April 11, 2012 10:10 AM