Skip to main content
Microsoft Silverlight
Home Forums Silverlight Programming Programming with .NET - General How to get multiple xaml in single page?
9 replies. Latest Post by JaishreeMCA on February 19, 2009.
(0)
JaishreeMCA
Member
20 points
17 Posts
01-23-2009 1:11 AM |
How to get multiple xaml in single page, like header xaml, body xaml and footer xaml in single xaml page?
jackbond
Contributor
2896 points
745 Posts
01-23-2009 1:40 AM |
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
Participant
1142 points
211 Posts
01-23-2009 1:41 AM |
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.
01-23-2009 2:15 AM |
This is what exactly I need. Can you give the sample code how to swap to need control?
silverli...
455 points
105 Posts
01-25-2009 8:46 AM |
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
Rafiqahamed
62 points
19 Posts
01-25-2009 2:42 PM |
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; }
01-27-2009 1:09 AM |
Thanx for your code. Its working fine.
01-28-2009 12:20 AM |
I was tried to do what you have said but I am getting exception while runtime:
{
InitializeComponent();
}
Header.Children.Add(TheHeader);
Exception :"Page can have only Window or Frame as parent."
What I have to do?
02-07-2009 8:47 AM |
u solved your problem ? otherwise post the code and XAML AND xaml.cs
02-19-2009 5:16 AM |
public partial class Login : Page
public
HeaderPart.Content = TheHeader;