WPF: Load Window inside Grid frame












0















I have WPF application and ListBoxItems as right Menu.



When specific ListBoxItem Islected i want to load different Window that i created called Home (instead of create several Grid elements and changed its Visibility) so i have this Grid:



<Grid>
<Frame Name="MyFrame"/>
</Grid>


And when the specific ListBoxItem Islected:



MyFrame.Content = new Home();


And got this error:




System.InvalidOperationException: ''MyApplication.Home' root element
is not valid for navigation.




'



Is this the right way to load other Window/Page ?










share|improve this question



























    0















    I have WPF application and ListBoxItems as right Menu.



    When specific ListBoxItem Islected i want to load different Window that i created called Home (instead of create several Grid elements and changed its Visibility) so i have this Grid:



    <Grid>
    <Frame Name="MyFrame"/>
    </Grid>


    And when the specific ListBoxItem Islected:



    MyFrame.Content = new Home();


    And got this error:




    System.InvalidOperationException: ''MyApplication.Home' root element
    is not valid for navigation.




    '



    Is this the right way to load other Window/Page ?










    share|improve this question

























      0












      0








      0








      I have WPF application and ListBoxItems as right Menu.



      When specific ListBoxItem Islected i want to load different Window that i created called Home (instead of create several Grid elements and changed its Visibility) so i have this Grid:



      <Grid>
      <Frame Name="MyFrame"/>
      </Grid>


      And when the specific ListBoxItem Islected:



      MyFrame.Content = new Home();


      And got this error:




      System.InvalidOperationException: ''MyApplication.Home' root element
      is not valid for navigation.




      '



      Is this the right way to load other Window/Page ?










      share|improve this question














      I have WPF application and ListBoxItems as right Menu.



      When specific ListBoxItem Islected i want to load different Window that i created called Home (instead of create several Grid elements and changed its Visibility) so i have this Grid:



      <Grid>
      <Frame Name="MyFrame"/>
      </Grid>


      And when the specific ListBoxItem Islected:



      MyFrame.Content = new Home();


      And got this error:




      System.InvalidOperationException: ''MyApplication.Home' root element
      is not valid for navigation.




      '



      Is this the right way to load other Window/Page ?







      wpf grid window






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 18 at 14:09









      user979033user979033

      4632724




      4632724
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Home must be a Page or a UserControl. You can't set the Content property of a Frame to an instance of a Window.



          If you want navigation history, you should consider using the NavigationService of the Frame to navigate to a page:



          MyFrame.NavigationService.Navigate(new Uri("Home.xaml", UriKind.Relative));





          share|improve this answer
























          • What is the different between Window and Page ?

            – user979033
            Jan 18 at 14:29











          • Well, it's two different types. A window is a floating top-level thing only. It cannot be the child of any other element.

            – mm8
            Jan 18 at 14:32











          • So if i want to load every ListBoxItem different Window with elements can i use Page as well ?

            – user979033
            Jan 18 at 15:04











          • You can set the Content property of the Frame to a Page that contains whatever you want to display.

            – mm8
            Jan 18 at 15:05











          • i want to register to my ListBox SelectionChanged event and i have 3 ListBoxItems and 3 pages and every index will how different Page, whan show specific Page what to do with the Current Page that need to Disappear ?

            – user979033
            Jan 18 at 15:21











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54255709%2fwpf-load-window-inside-grid-frame%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Home must be a Page or a UserControl. You can't set the Content property of a Frame to an instance of a Window.



          If you want navigation history, you should consider using the NavigationService of the Frame to navigate to a page:



          MyFrame.NavigationService.Navigate(new Uri("Home.xaml", UriKind.Relative));





          share|improve this answer
























          • What is the different between Window and Page ?

            – user979033
            Jan 18 at 14:29











          • Well, it's two different types. A window is a floating top-level thing only. It cannot be the child of any other element.

            – mm8
            Jan 18 at 14:32











          • So if i want to load every ListBoxItem different Window with elements can i use Page as well ?

            – user979033
            Jan 18 at 15:04











          • You can set the Content property of the Frame to a Page that contains whatever you want to display.

            – mm8
            Jan 18 at 15:05











          • i want to register to my ListBox SelectionChanged event and i have 3 ListBoxItems and 3 pages and every index will how different Page, whan show specific Page what to do with the Current Page that need to Disappear ?

            – user979033
            Jan 18 at 15:21
















          1














          Home must be a Page or a UserControl. You can't set the Content property of a Frame to an instance of a Window.



          If you want navigation history, you should consider using the NavigationService of the Frame to navigate to a page:



          MyFrame.NavigationService.Navigate(new Uri("Home.xaml", UriKind.Relative));





          share|improve this answer
























          • What is the different between Window and Page ?

            – user979033
            Jan 18 at 14:29











          • Well, it's two different types. A window is a floating top-level thing only. It cannot be the child of any other element.

            – mm8
            Jan 18 at 14:32











          • So if i want to load every ListBoxItem different Window with elements can i use Page as well ?

            – user979033
            Jan 18 at 15:04











          • You can set the Content property of the Frame to a Page that contains whatever you want to display.

            – mm8
            Jan 18 at 15:05











          • i want to register to my ListBox SelectionChanged event and i have 3 ListBoxItems and 3 pages and every index will how different Page, whan show specific Page what to do with the Current Page that need to Disappear ?

            – user979033
            Jan 18 at 15:21














          1












          1








          1







          Home must be a Page or a UserControl. You can't set the Content property of a Frame to an instance of a Window.



          If you want navigation history, you should consider using the NavigationService of the Frame to navigate to a page:



          MyFrame.NavigationService.Navigate(new Uri("Home.xaml", UriKind.Relative));





          share|improve this answer













          Home must be a Page or a UserControl. You can't set the Content property of a Frame to an instance of a Window.



          If you want navigation history, you should consider using the NavigationService of the Frame to navigate to a page:



          MyFrame.NavigationService.Navigate(new Uri("Home.xaml", UriKind.Relative));






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 18 at 14:17









          mm8mm8

          82.9k81831




          82.9k81831













          • What is the different between Window and Page ?

            – user979033
            Jan 18 at 14:29











          • Well, it's two different types. A window is a floating top-level thing only. It cannot be the child of any other element.

            – mm8
            Jan 18 at 14:32











          • So if i want to load every ListBoxItem different Window with elements can i use Page as well ?

            – user979033
            Jan 18 at 15:04











          • You can set the Content property of the Frame to a Page that contains whatever you want to display.

            – mm8
            Jan 18 at 15:05











          • i want to register to my ListBox SelectionChanged event and i have 3 ListBoxItems and 3 pages and every index will how different Page, whan show specific Page what to do with the Current Page that need to Disappear ?

            – user979033
            Jan 18 at 15:21



















          • What is the different between Window and Page ?

            – user979033
            Jan 18 at 14:29











          • Well, it's two different types. A window is a floating top-level thing only. It cannot be the child of any other element.

            – mm8
            Jan 18 at 14:32











          • So if i want to load every ListBoxItem different Window with elements can i use Page as well ?

            – user979033
            Jan 18 at 15:04











          • You can set the Content property of the Frame to a Page that contains whatever you want to display.

            – mm8
            Jan 18 at 15:05











          • i want to register to my ListBox SelectionChanged event and i have 3 ListBoxItems and 3 pages and every index will how different Page, whan show specific Page what to do with the Current Page that need to Disappear ?

            – user979033
            Jan 18 at 15:21

















          What is the different between Window and Page ?

          – user979033
          Jan 18 at 14:29





          What is the different between Window and Page ?

          – user979033
          Jan 18 at 14:29













          Well, it's two different types. A window is a floating top-level thing only. It cannot be the child of any other element.

          – mm8
          Jan 18 at 14:32





          Well, it's two different types. A window is a floating top-level thing only. It cannot be the child of any other element.

          – mm8
          Jan 18 at 14:32













          So if i want to load every ListBoxItem different Window with elements can i use Page as well ?

          – user979033
          Jan 18 at 15:04





          So if i want to load every ListBoxItem different Window with elements can i use Page as well ?

          – user979033
          Jan 18 at 15:04













          You can set the Content property of the Frame to a Page that contains whatever you want to display.

          – mm8
          Jan 18 at 15:05





          You can set the Content property of the Frame to a Page that contains whatever you want to display.

          – mm8
          Jan 18 at 15:05













          i want to register to my ListBox SelectionChanged event and i have 3 ListBoxItems and 3 pages and every index will how different Page, whan show specific Page what to do with the Current Page that need to Disappear ?

          – user979033
          Jan 18 at 15:21





          i want to register to my ListBox SelectionChanged event and i have 3 ListBoxItems and 3 pages and every index will how different Page, whan show specific Page what to do with the Current Page that need to Disappear ?

          – user979033
          Jan 18 at 15:21


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54255709%2fwpf-load-window-inside-grid-frame%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Homophylophilia

          Updating UILabel text programmatically using a function

          Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage