![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| 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 | |||