locked
Navigate Frame Reference

    Question

  • Hello.
    I try to create a Windows Store 8.1 App and i have a problem with the navigation of two pages.


    In the Mainpage i have a Object of the class ViewModel.
         Viewmodel Mainviewmodel = new Viewmodel();
        
    Now i try to transfer the reference of the object to a new page.
         Frame.Navigate(typeof(secondpage), ref Mainviewmodel);


    This does not work. What i have done wrong?

    thank you.

    Thursday, December 11, 2014 7:29 AM

Answers

  • If it's a big object , suggest add a static property in App.xaml.cs, so every page can access it. (But don't load data in App.xaml.cs, you can load data for this property in page's OnNavigateTo , or LoadState Method)

    Or if it's not so big, you can serialize it to json or xml string , pass it, then deserialize it on next page.


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Thursday, December 11, 2014 10:23 AM

All replies

  • (1) The second argument of  Frame.Navigate is by value not by refrence. so, you can't use "ref".

    (2) There is a limitation of this second argument's type,

    see: Frame.Navigate(TypeName, Object) method 

    To enable frame state serialization using GetNavigationState, you must use only basic types for the navigation parameter, such as string, char, numeric, and GUID types. Otherwise GetNavigationState will throw an exception when the app suspends. The parameter can have other types if you do not use GetNavigationState.


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Thursday, December 11, 2014 7:36 AM
  • Okay. I understand the problem.
    Now i need a other option to transfer a reference of a object.
    On the Second Page i want update arguments of the object
    and automatically shown on the mainpage.
    Thursday, December 11, 2014 8:25 AM
  • If it's a big object , suggest add a static property in App.xaml.cs, so every page can access it. (But don't load data in App.xaml.cs, you can load data for this property in page's OnNavigateTo , or LoadState Method)

    Or if it's not so big, you can serialize it to json or xml string , pass it, then deserialize it on next page.


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Thursday, December 11, 2014 10:23 AM