locked
Popup help on navigation or data passing.

    Question

  • I  use the SDK sample for Popup
    http://code.msdn.microsoft.com/windowsapps/Basic-Controls-29318599

    I want to make something like, after a game is finished. There will be a popup asking the user if he wants to go to the next level or go back to menu.
    Unfortunately, I can't navigate from my popup.

    I'm looking for an answer on either passing a data from popup to it's parent.
    or
    navigate from popup and it will change the parent

    Thanks for the always helpful answers :)
    Friday, March 22, 2013 12:12 PM

Answers

  • Navigation is indeed performed from Page to Page. So, when a Popup is involved, the following scenario is possible:
    - create the Popup in the Page and open it [IsOpen=true]
    - accept any data from user in the Popup
    - on Popup close, return the user data to the Page[*]
    - based on the data, navigate to the wanted Page

    [*] Refering to How to pass object from popup to its parent ? I can provide you with some additional détails:
    - when you create the Popup you set its DataContext to an instance of a Singleton class [in the example, 'Items' delivers only 1 instance thru its static 'Singleton' property]
    - the Popup UserControl binds any Textbox, etc... widget to a property of the single instance thru Text={Binding Path=WhatNext, Mode=TwoWay}
    - since the DataContext has been set to an instance of 'Items', the property 'WhatNext' will contain the user choice [possibly a default value to start with has been set by the Parent before opeing the Popup]
    - upon closing the popup, the close event is caught by the parent Page
    - you retrieve now any information to navigate to a new Page from the property 'WhatNext' in the instance pointed at by Items.Singleton.

    • Marked as answer by Franz_Justin Friday, March 22, 2013 2:35 PM
    Friday, March 22, 2013 1:16 PM

All replies

  • Navigation is indeed performed from Page to Page. So, when a Popup is involved, the following scenario is possible:
    - create the Popup in the Page and open it [IsOpen=true]
    - accept any data from user in the Popup
    - on Popup close, return the user data to the Page[*]
    - based on the data, navigate to the wanted Page

    [*] Refering to How to pass object from popup to its parent ? I can provide you with some additional détails:
    - when you create the Popup you set its DataContext to an instance of a Singleton class [in the example, 'Items' delivers only 1 instance thru its static 'Singleton' property]
    - the Popup UserControl binds any Textbox, etc... widget to a property of the single instance thru Text={Binding Path=WhatNext, Mode=TwoWay}
    - since the DataContext has been set to an instance of 'Items', the property 'WhatNext' will contain the user choice [possibly a default value to start with has been set by the Parent before opeing the Popup]
    - upon closing the popup, the close event is caught by the parent Page
    - you retrieve now any information to navigate to a new Page from the property 'WhatNext' in the instance pointed at by Items.Singleton.

    • Marked as answer by Franz_Justin Friday, March 22, 2013 2:35 PM
    Friday, March 22, 2013 1:16 PM
  • Uhm wait I don't get half of what you said (I'm not that in depth with c# )  but I think I got the idea you want to say,

    The pop up will open
    then it has 2 butons (Next and Home)
    If I click Next, there is an object(textblock) will change it's text to the address of the next level
    and also the same thing with Home.
    Then after that the popup will close
    and an event of having the popup close will trigger

    Is that right?

    Please explain the things I think I miss or misunderstood.

    Also I have some few questions, what event is the is close event?
    I mean what it's parameter :( How can the parent detect his child close?
    What is the Singleton Class?


    Friday, March 22, 2013 1:52 PM
  • "Also I have some few questions, what event is the is close event?
    I mean what it's parameter :( How can the parent detect his child close?
    What is the Singleton Class?"

    The example in entry "Tuesday, September 25, 2012 1:56 PM" in the referenced link provides the answers to those questions. I would recommend to create it in a new Project, so that you get acquainted with those important concepts.

    ---

    " The pop up will open
    then it has 2 butons (Next and Home)

    If I click Next, there is an object(textblock) will change it's text to the address of the next level
    and also the same thing with Home."

    With respect to the Buttons,
    - in the example UserControl,
      . you retain only the <Button Grid.Row="2" Content="Hit to close" Click="ClosePopup" FontSize="21" Background="Blue"/>.
      . The ListView is unnecessary in your scenario.
      . you create 1 Button representing a Next and 1 button representing a Home

    - upon 'Click' of one of the 2 buttons, the respective event Handler:
      . writes the 'Type of the next/home Page' to the 'WhatNext' property in the Singleton instance.
      . that instance is indeed the DataContext of the UserControl;
      . hence you can access the 'WhatNextProperty' as follows: "Items mySingleton=this.DataContext as Items".
      . closes the Popup as in the example

    - the usage of a TextBlock is in your scenario not required.


    • Edited by ForInfo Friday, March 22, 2013 2:32 PM
    Friday, March 22, 2013 2:29 PM
  • The link you provide is very useful, it's just that hard to grasp because I'm reverse engineering the code in the Link
    but nevertheless it's quite useful thanks :)
    Friday, March 22, 2013 2:33 PM
  • You will use those concepts over and over again ... so no waisted time in understanding how the example works :-)
    Friday, March 22, 2013 2:37 PM