show a page inside a window in XAML

17,799
<TabItem>
  <Frame Source="MyPage.xaml" />
</TabItem>
Share:
17,799
Steinthor.palsson
Author by

Steinthor.palsson

Updated on June 29, 2022

Comments

  • Steinthor.palsson
    Steinthor.palsson almost 2 years

    I have a tabcontrol in my window, inside each tabitem I want to have a different page.
    I can achieve this by making a Frame inside the TabItem and in the behind code use for example:

    frame1.Content = new Pages.MyPage()  
    

    How can I do the same thing in XAML?

  • Steinthor.palsson
    Steinthor.palsson about 13 years
    The first solution results in an InvalidOperationException: "page can only have window or frame as a parent". The second one, "Frame does not support direct content".
  • dcarneiro
    dcarneiro about 13 years
    Does MyPage extends UserControl? If not, which class does it extend?
  • Steinthor.palsson
    Steinthor.palsson about 13 years
    I don't know. It's just a normal page. How would I know that?
  • Steinthor.palsson
    Steinthor.palsson about 13 years
    hah... that simple. Thanks. It won't show up in the designer though. Maybe it's not possible?
  • Y.Yanavichus
    Y.Yanavichus about 13 years
    @steini: I dont't know. I never use designer :)
  • Stígandr
    Stígandr over 10 years
    steini: <Frame><Frame.Content><MyPage/></Frame.Content></Frame>