locked
overwriting Window::Current->Content

    Question

  • Hi,

    What i want to achieve:

    Window::Current->Content = ref new MainWindow; // Mainwindows inherits from usercontrol

    Window::Current->Activate();

    In MainWindow there is a button. when clicked do something like this:

    MainWindow::ButtonClicked(…)

    {

    Window::Current->Content = ref new Sub1Window; // Sub1Window inherits from usercontrol

    Window::Current->Activate();

    }

    In Sub1Window there is a button. when clicked do something like this:

    Sub1Window::ButtonClicked(…)

    {

    Window::Current->Content = ref new Sub2Window; // Sub2Window inherits from usercontrol AND it includes an AppBar

    Window::Current->Activate();

    }

    In Sub2Window there is a button. when clicked do something like this:

    Sub2Window::ButtonClicked(…)

    {

    Window::Current->Content = ref new MainWindow; // MainWindow inherits from usercontrol

    Window::Current->Activate();

    }

    So bascially clicking we have a Loop from MainWindow -> Sub1Window -> Sub2Window -> MainWindow -> Sub1Window ...

    Doing this: MainWindow -> Sub1Window -> Sub2Window -> MainWindow -> Sub1Window

    works for me.

    But doing this: MainWindow -> Sub1Window -> Sub2Window -> MainWindow -> Sub1Window -> !! Sub2Window !!

    hangs when in last Sub1Window the button is clicked.

    the Problem seems to be the appbar. without the appbar it works just fine.

    What is wrong with my pattern?

    When and how i should overwrite Window::Current->Content to get to a new usercontrol/page ?

    I know there is Frame and Frame::Navigate but using this my destructor of the previous usercontrol is not called. i would like to have full control of the LifeCycle of a UserControl/Page set to Window::Current->Content.

    sure when i call

    Window::Current->Content = ref new Sub2Window;

    from Sub1Window where this class object is set as Window::Current->Content this forces the destructor of Sub1Window to get called. is this a problem?

    there are no sample apps which Show how to achieve what i want.

    Thursday, March 8, 2012 10:42 AM

All replies

  • Nope I think when you new a new window. It should be a single object in memory, not the same as front one.

    NEU_ShieldEdge

    Friday, March 9, 2012 1:21 PM