Skip to main content

Answered Question How to get multiple xaml in single page? RSS Feed

(0)

JaishreeMCA
JaishreeMCA

Member

Member

20 points

17 Posts

How to get multiple xaml in single page?

How to get multiple xaml in single page, like header xaml, body xaml and footer xaml in single xaml page?

jackbond
jackbond

Contributor

Contributor

2896 points

745 Posts

Re: How to get multiple xaml in single page?

For one of my apps, my App.Xml loads a "master" page that is essentially a grid with 3 rows. While the header and footer rows don't change, the code behind for the master page swaps various user controls into the middle row on demand. So for example, my app starts at the login page. Once a user has successfully logged in, it raises an event that the master page handles and swaps in the lobby control.

MarkBetz
MarkBetz

Participant

Participant

1142 points

211 Posts

Re: How to get multiple xaml in single page?

I wondered about "server-side includes" when I first looked at Silverlight too :). But I'm not aware of anything like that. Fortunately there are a bunch of ways to do what you want. The most straightforward would be to have a Header user control, a Body user control, etc. Each user control can be in charge of loading and managing its own content. If you wish that content can be XAML that you dynamically download and instantiate.

JaishreeMCA
JaishreeMCA

Member

Member

20 points

17 Posts

Re: Re: How to get multiple xaml in single page?

This is what exactly I need. Can you give the sample code how to swap to need control?

 

silverlight_kid
silverli...

Member

Member

455 points

105 Posts

Answered Question

Re: Re: How to get multiple xaml in single page?

by my assumption

You have Main.xaml this is  the Main XAML you load

Main.xaml

<Canvas x:Name="LayoutRoot">

 <Canvas Canvas.Top="0"  x:Name="HeaderSection />

<Canvas x:Name="MiddleContent"  Height="somePixels" />

<Canvas x:Name="Footer" />

</Canvas>

Now you have 3  Pages for your website namely subpage1.xaml,subpage2.xaml,subpage2.xaml

in Main.xaml.cs loading

subpage1 mypage = new subpage1();

 

MiddleContent.Children.Add(mypage);

then to load secondpage

subpage2 mypage2 = new subpage2();

MiddleContent.Children.clear or remove what ever u wish;

MiddleContent.Children.Add(mypage2);

iily you can add and remove

 

If it is answer your question mark as answer bcoz other with same question can benefit

S.Siva Sankar
Software Engineer
Protechsoft

Rafiqahamed
Rafiqahamed

Member

Member

62 points

19 Posts

Answered Question

Re: How to get multiple xaml in single page?

hi

try this code 

Xmal Code:

  <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel Width="640" Height="480" HorizontalAlignment="Left" VerticalAlignment="Top" >
            <Border Height="160" x:Name="HeadArea"/>
            <Border Height="160" x:Name="MidArea"/>
            <Border Height="160" x:Name="BotArea"/>
        </StackPanel>
    </Grid>

 CS Code:

Public partial class Page : UserControl
    {

        headPage ha = new headPage();
        botpage bp = new botpage();
        Midpage mp = new Midpage();
      
        public Page()
        {
           InitializeComponent();
           HeadArea.Child = ha;
           MidArea.Child = mp;
           BotArea.Child = bp;
        }

 


 

 

JaishreeMCA
JaishreeMCA

Member

Member

20 points

17 Posts

Re: Re: How to get multiple xaml in single page?

Thanx for your code. Its working fine.

 

JaishreeMCA
JaishreeMCA

Member

Member

20 points

17 Posts

Re: Re: How to get multiple xaml in single page?

 I was tried to do what you have said but I am getting exception while runtime:

HeaderPage TheHeader = new HeaderPage();public HomePage()

{

InitializeComponent();

this.Loaded += new RoutedEventHandler(HomePage_Loaded);

}

void HomePage_Loaded(object sender, RoutedEventArgs e)

{

Header.Children.Add(TheHeader);

}

Exception :"Page can have only Window or Frame as parent."

What I have to do? 

 

silverlight_kid
silverli...

Member

Member

455 points

105 Posts

Re: Re: How to get multiple xaml in single page?

hi

u solved your problem ? otherwise post the code and XAML AND xaml.cs

S.Siva Sankar
Software Engineer
Protechsoft

JaishreeMCA
JaishreeMCA

Member

Member

20 points

17 Posts

Re: Re: How to get multiple xaml in single page?

public partial class Login : Page

{

public Login()

{

InitializeComponent();

HeaderPage TheHeader = new HeaderPage();

HeaderPart.Content = TheHeader;

}

}

  • Unanswered Question
  • Answered Question
  • Announcement