Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - How to Compose a Page From Grids Defined Outide the Page?

 
 
Old 11-10-2006   #1 (permalink)
Chris Moore


 
 

How to Compose a Page From Grids Defined Outide the Page?

Consider the following Scenario:

I have a xaml project which contains 3 grids defined in separate XAML
files, e.g.,

Grid1.xaml
-----------------------
<Grid x:Class="Grid1">
//content
</Grid>

Grid2.xaml
-----------------------
<Grid x:Class="Grid2">
//content
</Grid>

Grid3.xaml
-----------------------
<Grid x:Class="Grid3">
//content
</Grid>

Now, How does one construct a page that displays these grids in, say, a
Stack Panel?

Thanks


My System SpecsSystem Spec
Old 11-10-2006   #2 (permalink)
Bob


 
 

Re: How to Compose a Page From Grids Defined Outide the Page?

In article <1163173383.530241.170150@h54g2000cwb.googlegroups.com>,
CMoore@gmail.com says...
> Consider the following Scenario:
>
> I have a xaml project which contains 3 grids defined in separate XAML
> files, e.g.,
>
> Grid1.xaml
> -----------------------
> <Grid x:Class="Grid1">
> //content
> </Grid>
>
> Grid2.xaml
> -----------------------
> <Grid x:Class="Grid2">
> //content
> </Grid>
>
> Grid3.xaml
> -----------------------
> <Grid x:Class="Grid3">
> //content
> </Grid>
>
> Now, How does one construct a page that displays these grids in, say, a
> Stack Panel?
>
> Thanks
>
>


Given 3 XAML files in the same directory as the exe..

<!-- xaml1.xaml -->
<Button
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
Buton1</Button>

<!-- xaml2.xaml -->
<Button
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
Buton1</Button>

<!-- xaml3.xaml -->
<Button
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
Buton1</Button>

this XAML...

<Window x:Class="buildGUIviaXamlReader.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="buildGUIviaXamlReader" Height="300" Width="300"
>

<Grid Name="Grid1" Loaded="Grid1_Loaded">
<StackPanel Name="stackPanel1" />
</Grid>
</Window>

Married with this code behind... should do the trick

using System;
using System.Windows;
using System.Windows.Markup; //XamlReader
using System.IO;
using System.Xml;

namespace buildGUIviaXamlReader
{
public partial class Window1 : System.Windows.Window
{
public Window1()
{
InitializeComponent();
this.Grid1.Loaded += new RoutedEventHandler(Grid1
_Loaded);
}

void Grid1_Loaded(object sender, RoutedEventArgs e)
{
stackPanel1.Children.Clear();
LoadSomeXaml("xaml1.xaml");
LoadSomeXaml("xaml2.xaml");
LoadSomeXaml("xaml3.xaml");
}

protected void LoadSomeXaml(string Xaml)
{
try
{
XmlTextReader xmlreader = new XmlTextReader
(Xaml);
UIElement el = (UIElement)XamlReader.Load
(xmlreader);
this.stackPanel1.Children.Add(el);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, Title);
}
}
}
}
My System SpecsSystem Spec
Old 11-11-2006   #3 (permalink)
Chris Moore


 
 

Re: How to Compose a Page From Grids Defined Outide the Page?

Bog,

Thanks for your response and the example.

Is there no declarative way that this can be accomplished via XAML
only? I would like to be able to build the page that is composed of the
grids entirely in XAML.


There must be a simple way to do this but after much searching I cannot
find an example.

Chris.

Bob wrote:
> In article <1163173383.530241.170150@h54g2000cwb.googlegroups.com>,
> CMoore@gmail.com says...
> > Consider the following Scenario:
> >
> > I have a xaml project which contains 3 grids defined in separate XAML
> > files, e.g.,
> >
> > Grid1.xaml
> > -----------------------
> > <Grid x:Class="Grid1">
> > //content
> > </Grid>
> >
> > Grid2.xaml
> > -----------------------
> > <Grid x:Class="Grid2">
> > //content
> > </Grid>
> >
> > Grid3.xaml
> > -----------------------
> > <Grid x:Class="Grid3">
> > //content
> > </Grid>
> >
> > Now, How does one construct a page that displays these grids in, say, a
> > Stack Panel?
> >
> > Thanks
> >
> >

>
> Given 3 XAML files in the same directory as the exe..
>
> <!-- xaml1.xaml -->
> <Button
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
> Buton1</Button>
>
> <!-- xaml2.xaml -->
> <Button
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
> Buton1</Button>
>
> <!-- xaml3.xaml -->
> <Button
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
> Buton1</Button>
>
> this XAML...
>
> <Window x:Class="buildGUIviaXamlReader.Window1"
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> Title="buildGUIviaXamlReader" Height="300" Width="300"
> >

> <Grid Name="Grid1" Loaded="Grid1_Loaded">
> <StackPanel Name="stackPanel1" />
> </Grid>
> </Window>
>
> Married with this code behind... should do the trick
>
> using System;
> using System.Windows;
> using System.Windows.Markup; //XamlReader
> using System.IO;
> using System.Xml;
>
> namespace buildGUIviaXamlReader
> {
> public partial class Window1 : System.Windows.Window
> {
> public Window1()
> {
> InitializeComponent();
> this.Grid1.Loaded += new RoutedEventHandler(Grid1
> _Loaded);
> }
>
> void Grid1_Loaded(object sender, RoutedEventArgs e)
> {
> stackPanel1.Children.Clear();
> LoadSomeXaml("xaml1.xaml");
> LoadSomeXaml("xaml2.xaml");
> LoadSomeXaml("xaml3.xaml");
> }
>
> protected void LoadSomeXaml(string Xaml)
> {
> try
> {
> XmlTextReader xmlreader = new XmlTextReader
> (Xaml);
> UIElement el = (UIElement)XamlReader.Load
> (xmlreader);
> this.stackPanel1.Children.Add(el);
> }
> catch (Exception exc)
> {
> MessageBox.Show(exc.Message, Title);
> }
> }
> }
> }


My System SpecsSystem Spec
Old 11-11-2006   #4 (permalink)
Pon


 
 

Re: How to Compose a Page From Grids Defined Outide the Page?

Do I understand well what u want ? Because I don't really see where the
trouble is. Why don't u make these grids application scope resources ?

"Chris Moore" <CMoore@gmail.com> a écrit dans le message de news:
1163173383.530241.170150@h54g2000cwb.googlegroups.com...
> Consider the following Scenario:
>
> I have a xaml project which contains 3 grids defined in separate XAML
> files, e.g.,
>
> Grid1.xaml
> -----------------------
> <Grid x:Class="Grid1">
> //content
> </Grid>
>
> Grid2.xaml
> -----------------------
> <Grid x:Class="Grid2">
> //content
> </Grid>
>
> Grid3.xaml
> -----------------------
> <Grid x:Class="Grid3">
> //content
> </Grid>
>
> Now, How does one construct a page that displays these grids in, say, a
> Stack Panel?
>
> Thanks
>



My System SpecsSystem Spec
Old 11-11-2006   #5 (permalink)
Douglas Stockwell


 
 

Re: How to Compose a Page From Grids Defined Outide the Page?

Read up on namespace declarations. You should be able to do the following:

<Window xmlns:local="clr-namespace:YourNamespace">
<StackPanel>
<local:Grid1 />
<local:Grid2 />
<local:Grid3 />
</StackPanel>
</Window>

- Doug

"Chris Moore" <CMoore@gmail.com> wrote in message
news:1163223265.763237.287150@m7g2000cwm.googlegroups.com...
> Bog,
>
> Thanks for your response and the example.
>
> Is there no declarative way that this can be accomplished via XAML
> only? I would like to be able to build the page that is composed of the
> grids entirely in XAML.
>
>
> There must be a simple way to do this but after much searching I cannot
> find an example.
>
> Chris.
>
> Bob wrote:
>> In article <1163173383.530241.170150@h54g2000cwb.googlegroups.com>,
>> CMoore@gmail.com says...
>> > Consider the following Scenario:
>> >
>> > I have a xaml project which contains 3 grids defined in separate XAML
>> > files, e.g.,
>> >
>> > Grid1.xaml
>> > -----------------------
>> > <Grid x:Class="Grid1">
>> > //content
>> > </Grid>
>> >
>> > Grid2.xaml
>> > -----------------------
>> > <Grid x:Class="Grid2">
>> > //content
>> > </Grid>
>> >
>> > Grid3.xaml
>> > -----------------------
>> > <Grid x:Class="Grid3">
>> > //content
>> > </Grid>
>> >
>> > Now, How does one construct a page that displays these grids in, say, a
>> > Stack Panel?
>> >
>> > Thanks
>> >
>> >

>>
>> Given 3 XAML files in the same directory as the exe..
>>
>> <!-- xaml1.xaml -->
>> <Button
>> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
>> Buton1</Button>
>>
>> <!-- xaml2.xaml -->
>> <Button
>> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
>> Buton1</Button>
>>
>> <!-- xaml3.xaml -->
>> <Button
>> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
>> Buton1</Button>
>>
>> this XAML...
>>
>> <Window x:Class="buildGUIviaXamlReader.Window1"
>> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>> Title="buildGUIviaXamlReader" Height="300" Width="300"
>> >

>> <Grid Name="Grid1" Loaded="Grid1_Loaded">
>> <StackPanel Name="stackPanel1" />
>> </Grid>
>> </Window>
>>
>> Married with this code behind... should do the trick
>>
>> using System;
>> using System.Windows;
>> using System.Windows.Markup; //XamlReader
>> using System.IO;
>> using System.Xml;
>>
>> namespace buildGUIviaXamlReader
>> {
>> public partial class Window1 : System.Windows.Window
>> {
>> public Window1()
>> {
>> InitializeComponent();
>> this.Grid1.Loaded += new RoutedEventHandler(Grid1
>> _Loaded);
>> }
>>
>> void Grid1_Loaded(object sender, RoutedEventArgs e)
>> {
>> stackPanel1.Children.Clear();
>> LoadSomeXaml("xaml1.xaml");
>> LoadSomeXaml("xaml2.xaml");
>> LoadSomeXaml("xaml3.xaml");
>> }
>>
>> protected void LoadSomeXaml(string Xaml)
>> {
>> try
>> {
>> XmlTextReader xmlreader = new XmlTextReader
>> (Xaml);
>> UIElement el = (UIElement)XamlReader.Load
>> (xmlreader);
>> this.stackPanel1.Children.Add(el);
>> }
>> catch (Exception exc)
>> {
>> MessageBox.Show(exc.Message, Title);
>> }
>> }
>> }
>> }

>


My System SpecsSystem Spec
Old 11-11-2006   #6 (permalink)
Chris Moore


 
 

Re: How to Compose a Page From Grids Defined Outide the Page?

Thanks; that worked like a charm and was exactly what I was looking
for. I knew there must be a simple way to do it.....



Douglas Stockwell wrote:
> Read up on namespace declarations. You should be able to do the following:
>
> <Window xmlns:local="clr-namespace:YourNamespace">
> <StackPanel>
> <local:Grid1 />
> <local:Grid2 />
> <local:Grid3 />
> </StackPanel>
> </Window>
>
> - Doug
>
> "Chris Moore" <CMoore@gmail.com> wrote in message
> news:1163223265.763237.287150@m7g2000cwm.googlegroups.com...
> > Bog,
> >
> > Thanks for your response and the example.
> >
> > Is there no declarative way that this can be accomplished via XAML
> > only? I would like to be able to build the page that is composed of the
> > grids entirely in XAML.
> >
> >
> > There must be a simple way to do this but after much searching I cannot
> > find an example.
> >
> > Chris.
> >
> > Bob wrote:
> >> In article <1163173383.530241.170150@h54g2000cwb.googlegroups.com>,
> >> CMoore@gmail.com says...
> >> > Consider the following Scenario:
> >> >
> >> > I have a xaml project which contains 3 grids defined in separate XAML
> >> > files, e.g.,
> >> >
> >> > Grid1.xaml
> >> > -----------------------
> >> > <Grid x:Class="Grid1">
> >> > //content
> >> > </Grid>
> >> >
> >> > Grid2.xaml
> >> > -----------------------
> >> > <Grid x:Class="Grid2">
> >> > //content
> >> > </Grid>
> >> >
> >> > Grid3.xaml
> >> > -----------------------
> >> > <Grid x:Class="Grid3">
> >> > //content
> >> > </Grid>
> >> >
> >> > Now, How does one construct a page that displays these grids in, say, a
> >> > Stack Panel?
> >> >
> >> > Thanks
> >> >
> >> >
> >>
> >> Given 3 XAML files in the same directory as the exe..
> >>
> >> <!-- xaml1.xaml -->
> >> <Button
> >> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
> >> Buton1</Button>
> >>
> >> <!-- xaml2.xaml -->
> >> <Button
> >> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
> >> Buton1</Button>
> >>
> >> <!-- xaml3.xaml -->
> >> <Button
> >> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
> >> Buton1</Button>
> >>
> >> this XAML...
> >>
> >> <Window x:Class="buildGUIviaXamlReader.Window1"
> >> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> >> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> >> Title="buildGUIviaXamlReader" Height="300" Width="300"
> >> >
> >> <Grid Name="Grid1" Loaded="Grid1_Loaded">
> >> <StackPanel Name="stackPanel1" />
> >> </Grid>
> >> </Window>
> >>
> >> Married with this code behind... should do the trick
> >>
> >> using System;
> >> using System.Windows;
> >> using System.Windows.Markup; //XamlReader
> >> using System.IO;
> >> using System.Xml;
> >>
> >> namespace buildGUIviaXamlReader
> >> {
> >> public partial class Window1 : System.Windows.Window
> >> {
> >> public Window1()
> >> {
> >> InitializeComponent();
> >> this.Grid1.Loaded += new RoutedEventHandler(Grid1
> >> _Loaded);
> >> }
> >>
> >> void Grid1_Loaded(object sender, RoutedEventArgs e)
> >> {
> >> stackPanel1.Children.Clear();
> >> LoadSomeXaml("xaml1.xaml");
> >> LoadSomeXaml("xaml2.xaml");
> >> LoadSomeXaml("xaml3.xaml");
> >> }
> >>
> >> protected void LoadSomeXaml(string Xaml)
> >> {
> >> try
> >> {
> >> XmlTextReader xmlreader = new XmlTextReader
> >> (Xaml);
> >> UIElement el = (UIElement)XamlReader.Load
> >> (xmlreader);
> >> this.stackPanel1.Children.Add(el);
> >> }
> >> catch (Exception exc)
> >> {
> >> MessageBox.Show(exc.Message, Title);
> >> }
> >> }
> >> }
> >> }

> >


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
page fault in no page area Vista installation & setup
page numbering past page 82 .NET General
Front page change index page? Vista networking & sharing
page disappears when Mouse moved off page General Discussion
Blue Screen - Page fault in non page area Vista performance & maintenance


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46