Load XAML File dynamically<P>Is this possible?&nbsp;&nbsp;&nbsp; </P> <P>I'm Beginner in winFX programming and I want to load a xaml file dynamically.&nbsp;&nbsp;&nbsp;</P> <P>For example I make an event handler which load the new Xaml Description from a uri (generated by another application) on event catched and load the new interface in a panel.</P> <P>Have you an example or a tutorial on it?</P> <P>Thanks for your help <IMG src="http://forums.microsoft.com/MSDN/images/emoticons/smile_embaressed.gif"></P> <P>&nbsp;</P>© 2009 Microsoft Corporation. All rights reserved.Thu, 04 Jun 2009 00:30:29 Za53ff197-8703-4c6c-8726-45570304fb7bhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#a53ff197-8703-4c6c-8726-45570304fb7bhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#a53ff197-8703-4c6c-8726-45570304fb7bXavier ALVAROhttp://social.msdn.microsoft.com/Profile/en-US/?user=Xavier%20ALVAROLoad XAML File dynamically<P>Is this possible?&nbsp;&nbsp;&nbsp; </P> <P>I'm Beginner in winFX programming and I want to load a xaml file dynamically.&nbsp;&nbsp;&nbsp;</P> <P>For example I make an event handler which load the new Xaml Description from a uri (generated by another application) on event catched and load the new interface in a panel.</P> <P>Have you an example or a tutorial on it?</P> <P>Thanks for your help <IMG src="http://forums.microsoft.com/MSDN/images/emoticons/smile_embaressed.gif"></P> <P>&nbsp;</P>Fri, 17 Mar 2006 10:28:16 Z2006-03-19T14:21:48Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#cbe88047-1c53-434e-afae-c6685f3332e4http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#cbe88047-1c53-434e-afae-c6685f3332e4_Michael_http://social.msdn.microsoft.com/Profile/en-US/?user=_Michael_Load XAML File dynamically<p>Have a look in the SDK WinFX samples for FlowDocument_LoadSave sample.  It does more or less what you need I think.</p> <p>Michael</p>Fri, 17 Mar 2006 13:15:14 Z2006-03-17T13:15:14Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#5d8b50e1-16d2-4800-b691-134254b73385http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#5d8b50e1-16d2-4800-b691-134254b73385Xavier ALVAROhttp://social.msdn.microsoft.com/Profile/en-US/?user=Xavier%20ALVAROLoad XAML File dynamically<p>Thanks,</p> <p>I tried this sample but it can only load FlowDocument, what I want to do is to load a panel with Button, Label etc.</p> <p>I'll try to modify the sample.</p> <p> </p> <p> </p>Fri, 17 Mar 2006 14:23:47 Z2006-03-17T14:23:47Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#2027a2fd-74e3-4ce4-bf9c-649b709dc568http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#2027a2fd-74e3-4ce4-bf9c-649b709dc568viliescuhttp://social.msdn.microsoft.com/Profile/en-US/?user=viliescuLoad XAML File dynamicallyUsing XamlReader you can load any element and set it as the content of your window/page.<br> <br> this.Content = XamlReader.Load(stream); <base><base>XamlReader.Fri, 17 Mar 2006 14:37:11 Z2006-03-19T14:21:48Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#e8429f7d-ca11-41f6-8c5c-5fe0b6e158ffhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#e8429f7d-ca11-41f6-8c5c-5fe0b6e158ffXavier ALVAROhttp://social.msdn.microsoft.com/Profile/en-US/?user=Xavier%20ALVAROLoad XAML File dynamically<P><FONT size=2>Thanks :)</FONT></P> <P><FONT size=2>I use XamlReader and it work but not completely, it "draw" my interface but don't rely with "functions".</FONT></P> <P><FONT size=2>This a example of my problem :</FONT></P> <P><FONT size=2>I have a cs file with a function which is described here :</FONT></P> <P><FONT color=#0000ff size=1>private void CompileXaml(String xamlDocument)</FONT></P> <P><FONT color=#0000ff size=1>{</FONT></P> <P><FONT color=#0000ff size=1>StringReader stringReader = null;</FONT></P> <P><FONT color=#0000ff size=1>XmlTextReader xmlReader = null;</FONT></P> <P><FONT color=#0000ff size=1>try</FONT></P> <P><FONT color=#0000ff size=1>{</FONT></P> <P><FONT color=#0000ff size=1>stringReader = new StringReader(xamlDocument);</FONT></P> <P><FONT color=#0000ff size=1>xmlReader = new XmlTextReader(stringReader);</FONT></P> <P><FONT color=#0000ff size=1>UIElement documentRoot = (UIElement)System.Windows.Markup.XamlReader.Load(xmlReader);</FONT></P> <P><FONT color=#0000ff size=1>interactionWindow.child&nbsp;= documentRoot;</FONT></P> <P><FONT color=#0000ff size=1>}</FONT></P> <P><FONT color=#0000ff size=1>catch (Exception ex)</FONT></P> <P><FONT color=#0000ff size=1>{</FONT><FONT color=#0000ff size=1>}</FONT></P> <P><FONT color=#0000ff size=1>finally</FONT></P> <P><FONT color=#0000ff size=1>{</FONT></P> <P><FONT color=#0000ff size=1>if (stringReader != null) stringReader.Close();</FONT></P> <P><FONT color=#0000ff size=1>if (xmlReader != null) xmlReader.Close();</FONT></P> <P><FONT color=#0000ff size=1>}</FONT></P> <P><FONT color=#0000ff size=1>}</FONT></P> <P><FONT color=#0000ff><FONT size=1>private void Close(object sender, RoutedEventArgs e)&nbsp; </FONT><FONT size=1>{ </FONT><FONT size=1>this.Close(); </FONT><FONT size=1>}</FONT></FONT></P> <P><FONT size=2>and i want to load dynamically the xaml description with xamlReader ( for example&nbsp; <FONT color=#000000><FONT color=#0000ff><FONT size=1>&lt;Button Name="btnOk"&nbsp;Click="Close"&gt;</FONT>&nbsp; </FONT><FONT color=#000000>or more complicated interaction </FONT>) </FONT></FONT><FONT color=#0000ff size=2><FONT color=#000000>with xamlreader, I can just load</FONT> <FONT size=1>&lt;Button Name="btnOk"&gt;</FONT></FONT></P> <P><FONT color=#000000>it says "you must compile",</FONT><FONT color=#000000> I'm really obligated?</FONT></P> <P><FONT size=2><FONT color=#0000ff>&nbsp;</P></FONT></FONT>Fri, 17 Mar 2006 15:41:15 Z2006-03-17T15:41:15Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#8ed87979-d0e5-4f6d-b952-4656c74b7876http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#8ed87979-d0e5-4f6d-b952-4656c74b7876Ashish Shetty - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Ashish%20Shetty%20-%20MSFTLoad XAML File dynamically<p><font size=2>There is no support for dynamically loading (or compiling) code behind or inline code with loose XAML.</font></p> <p><font size=2>There are a couple ways you can work around this:</font></p> <ol> <li><font size=2>Hook the event handlers via code, <br>e.g something like:<br></font> <p><font size=2>Page page = (Page)System.Windows.Markup.XamlReader.Load(xmlReader);<br><br>TextBox tb = page.FindName(<font color="#800000">&quot;firstName&quot;</font>) <font color="#0000ff">as</font> TextBox;</font></p> <p><font size=2><font color="#0000ff">if</font> (tb != <font color="#0000ff">null</font>)<br>tb.Text = <font color="#800000">&quot;Joe&quot;</font>;</font></p> <p><font size=2>Button btnOk = page.FindName(<font color="#800000">&quot;btnOk&quot;</font>) <font color="#0000ff">as</font> Button;</font></p> <p><font size=2><font color="#0000ff">if</font> (btnOk != <font color="#0000ff">null</font>)<br>btnOk.Click += <font color="#0000ff">new</font> RoutedEventHandler(btnOk_Click); <font color="#008000">// and add the btnOk_Click event handler below</font></font></p><br><font size=2>or<br></font></li> <li><font size=2>use a custom page with component, and hook the event handlers via component code</font></li></ol>Fri, 17 Mar 2006 20:18:10 Z2006-03-19T14:21:36Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#617831a3-0e49-45f3-b945-d0afc82922c4http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#617831a3-0e49-45f3-b945-d0afc82922c4Xavier ALVAROhttp://social.msdn.microsoft.com/Profile/en-US/?user=Xavier%20ALVAROLoad XAML File dynamically<p>Big thanks !!!!</p> <p>this is what i need !</p> <p> </p>Sun, 19 Mar 2006 14:21:09 Z2006-03-19T14:21:09Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#7ed51762-e93c-4ac1-997a-91522a63ad8chttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#7ed51762-e93c-4ac1-997a-91522a63ad8cJalenhttp://social.msdn.microsoft.com/Profile/en-US/?user=JalenLoad XAML File dynamically<p>Hi Ashish,</p> <p>Can you give an example for the 2nd option - using custom page with component? Thanks!</p>Wed, 29 Mar 2006 21:49:36 Z2006-03-29T21:49:36Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#74711647-23d4-4d76-9622-d541e5896b11http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#74711647-23d4-4d76-9622-d541e5896b11simsodhttp://social.msdn.microsoft.com/Profile/en-US/?user=simsodLoad XAML File dynamicallyI Second that motion! :)<br>Tue, 19 Dec 2006 11:00:51 Z2006-12-19T11:00:51Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#b51bf991-d087-402a-ae89-653f63f8ff90http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#b51bf991-d087-402a-ae89-653f63f8ff90Khalid Naseemhttp://social.msdn.microsoft.com/Profile/en-US/?user=Khalid%20NaseemLoad XAML File dynamicallyHi Guys!<br><br>I wish to create XAML files and have a single code behind for all the XAML files. How can I achieve this? This will help me in creating an engine which will contain the code for a common code behind and I would be able to introduce multiple XAML files to the engine and they would run with all its event handlers being picked from the common code behind. Please help me out on this.<br><br>Tue, 12 Jun 2007 10:29:17 Z2007-06-12T10:29:17Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#45e9bac8-de74-4cf4-9daa-8b5e16c9bbc3http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#45e9bac8-de74-4cf4-9daa-8b5e16c9bbc3Ryan Cromwellhttp://social.msdn.microsoft.com/Profile/en-US/?user=Ryan%20CromwellLoad XAML File dynamicallyFor those interested I used the following code snippet to &quot;skin&quot; my app.<br><br> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p>ResourceDictionary rd = null;<br>rd = Application.LoadComponent( new Uri( uri, UriKind.RelativeOrAbsolute ) ) as ResourceDictionary;<br><br>if( rd != null )<br>    Application.Current.Resources = rd;</p></div></div><br><br>I found this through Alan Le's blog <a title="http://blogs.vertigo.com/personal/AlanL/Blog/Lists/Posts/Post.aspx?ID=15" href="http://blogs.vertigo.com/personal/AlanL/Blog/Lists/Posts/Post.aspx?ID=15">post</a>.<br>Tue, 12 Jun 2007 14:27:03 Z2007-06-12T14:27:03Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#b030d4c4-ed6e-4f65-b709-c6c8264e4d0ehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#b030d4c4-ed6e-4f65-b709-c6c8264e4d0eniketuhttp://social.msdn.microsoft.com/Profile/en-US/?user=niketuLoad XAML File dynamically<p align=left><font face=Arial size=2>I am trying to create a XBAP application and I am having problems defining proper permissions to read a XAML file.</font></p> <p align=left> </p> <p align=left>Also, I tried this code using just a XML string, the code goes through but the Page does not change, I do not see the new controls loaded?</p> <p align=left> </p> <p align=left>How do you load a custom loaded page on the current page? Or do you have to navigate to the custom loaded page, if so how?</p> <p align=left> </p> <p align=left>Thank you for your help.</p>Thu, 06 Dec 2007 15:49:29 Z2007-12-06T15:49:29Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#2bf752e9-1bde-4a6e-8b12-4738929c2cbchttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#2bf752e9-1bde-4a6e-8b12-4738929c2cbcShadowmanXhttp://social.msdn.microsoft.com/Profile/en-US/?user=ShadowmanXLoad XAML File dynamically<div class=quote><font class=quoteHeader>Ashish Shetty - MSFT said:</font> <p></p> <p><font size=2>There is no support for dynamically loading (or compiling) code behind or inline code with loose XAML.</font></p> <p><font size=2>There are a couple ways you can work around this:</font></p> <ol> <li><font size=2>Hook the event handlers via code, <br> e.g something like:<br> </font> <p><font size=2>Page page = (Page)System.Windows.Markup.XamlReader.Load(xmlReader);<br> <br> TextBox tb = page.FindName(<font style="color:rgb(128, 0, 0)" color="#800000">&quot;firstName&quot;</font>) <font style="color:rgb(0, 0, 255)" color="#0000ff">as</font> TextBox;</font></p> <p><font size=2><font style="color:rgb(0, 0, 255)" color="#0000ff">if</font> (tb != <font style="color:rgb(0, 0, 255)" color="#0000ff">null</font>)<br> tb.Text = <font style="color:rgb(128, 0, 0)" color="#800000">&quot;Joe&quot;</font>;</font></p> <p><font size=2>Button btnOk = page.FindName(<font style="color:rgb(128, 0, 0)" color="#800000">&quot;btnOk&quot;</font>) <font style="color:rgb(0, 0, 255)" color="#0000ff">as</font> Button;</font></p> <p><font size=2><font style="color:rgb(0, 0, 255)" color="#0000ff">if</font> (btnOk != <font style="color:rgb(0, 0, 255)" color="#0000ff">null</font>)<br> btnOk.Click += <font style="color:rgb(0, 0, 255)" color="#0000ff">new</font> RoutedEventHandler(btnOk_Click); <font style="color:rgb(0, 128, 0)" color="#008000">// and add the btnOk_Click event handler below</font></font></p> <br> <font size=2>or<br> </font></li> <li><font size=2>use a custom page with component, and hook the event handlers via component code</font></li> </ol> <p></p> </div> I tried this, but I always get an exception:<br> <br> System.Windows.Markup.XamlParseException: Ungültige Daten auf Stammebene. Zeile 1, Position 1. ---&gt; System.Xml.XmlException: Ungültige Daten auf Stammebene. Zeile 1, Position 1.<br>    bei System.Xml.XmlTextReaderImpl.Throw(Exception e)<br>    bei System.Xml.XmlTextReaderImpl.Throw(String res, String arg)<br>    bei System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()<br>    bei System.Xml.XmlTextReaderImpl.ParseDocumentContent()<br>    bei System.Xml.XmlTextReaderImpl.Read()<br>    bei System.Xml.XmlTextReader.Read()<br>    bei System.Windows.Markup.XmlCompatibilityReader.Read()<br>    bei System.Windows.Markup.XamlReaderHelper.Read(XamlNode&amp; xamlNode)<br>    --- Ende der internen Ausnahmestapelüberwachung ---<br>    bei System.Windows.Markup.XamlReaderHelper.RethrowAsParseException(String keyString, Int32 lineNumber, Int32 linePosition, Exception innerException)<br>    bei System.Windows.Markup.XamlReaderHelper.Read(XamlNode&amp; xamlNode)<br>    bei System.Windows.Markup.XamlParser.ReadXaml(Boolean singleRecordMode)<br>    bei System.Windows.Markup.TreeBuilderXamlTranslator._Parse()<br>    bei System.Windows.Markup.XamlParser.Parse()<br>    bei System.Windows.Markup.XamlTreeBuilder.ParseFragment()<br>    bei System.Windows.Markup.TreeBuilder.Parse()<br>    bei System.Windows.Markup.XamlReader.XmlTreeBuildDefault(ParserContext pc, XmlReader reader, Boolean wrapWithMarkupCompatReader, XamlParseMode parseMode, Boolean etwTracingEnabled)<br>    bei System.Windows.Markup.XamlReader.Load(XmlReader reader)<br>    bei Skin_Test.Window1.MI_Load_Click(Object sender, RoutedEventArgs e) in C:\Dokumente und Einstellungen\christian.hauer\Eigene Dateien\Visual Studio 2008\Projects\Skin_Test\Skin_Test\Window1.xaml.cs:Zeile 163.<br> <br> <br> I only have it in german, sorry about that.<br> <br> My Code:<br> <br> <div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:courier new;font-size:11px"> <table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0> <col style="font-family:courier new;font-size:11px;padding-left:10px;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px"></font><font style="color:blue">try</font><font style="font-size:11px"> </font></td> </tr> <tr> <td style="background-color:rgb(247, 247, 247)">{ </td> </tr> <tr> <td>    StringReader stringReader = <font style="color:blue">new</font><font style="font-size:11px"> StringReader(</font><font style="color:blue">&quot;testload.xaml&quot;</font><font style="font-size:11px">); </font></td> </tr> <tr> <td style="background-color:rgb(247, 247, 247)">    XmlReader xmlReader = <font style="color:blue">new</font><font style="font-size:11px"> XmlTextReader(stringReader); </font></td> </tr> <tr> <td>    Page page = (Page)System.Windows.Markup.XamlReader.Load(xmlReader); </td> </tr> <tr> <td style="background-color:rgb(247, 247, 247)">} </td> </tr> <tr> <td><font style="color:blue">catch</font><font style="font-size:11px"> (Exception ex) </font></td> </tr> <tr> <td style="background-color:rgb(247, 247, 247)">{ </td> </tr> <tr> <td>    MessageBox.Show(ex.ToString(), <font style="color:blue">&quot;Error&quot;</font><font style="font-size:11px">); </font></td> </tr> <tr> <td style="background-color:rgb(247, 247, 247)">} </td> </tr> </tbody> </table> </div> <br> My XAML-File:<br><br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px"></font><font style="color:blue">&lt;</font><font style="font-size:11px">Grid </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">    <font style="color:red">xmlns</font><font style="font-size:11px">=</font><font style="color:blue">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</font><font style="font-size:11px"> </font></td></tr><tr><td>    xmlns:<font style="color:red">x</font><font style="font-size:11px">=</font><font style="color:blue">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">    xmlns:<font style="color:red">jas</font><font style="font-size:11px">=</font><font style="color:blue">&quot;clr-namespace:WPF.JoshSmith.Panels&quot;</font><font style="font-size:11px">&gt; </font></td></tr><tr><td>    <font style="color:blue">&lt;</font><font style="font-size:11px">jas:dragCanvas x:</font><font style="color:red">Name</font><font style="font-size:11px">=</font><font style="color:blue">&quot;dragCanvas&quot;</font><font style="font-size:11px">&gt; </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">        <font style="color:blue">&lt;</font><font style="font-size:11px">Button </font><font style="color:red">Name</font><font style="font-size:11px">=</font><font style="color:blue">&quot;testButton&quot;</font><font style="font-size:11px"> </font><font style="color:red">Width</font><font style="font-size:11px">=</font><font style="color:blue">&quot;100&quot;</font><font style="font-size:11px"> </font><font style="color:red">Height</font><font style="font-size:11px">=</font><font style="color:blue">&quot;30&quot;</font><font style="font-size:11px"> </font><font style="color:red">Canvas.Left</font><font style="font-size:11px">=</font><font style="color:blue">&quot;10&quot;</font><font style="font-size:11px"> </font><font style="color:red">Canvas.Top</font><font style="font-size:11px">=</font><font style="color:blue">&quot;20&quot;</font><font style="font-size:11px"> </font><font style="color:red">VerticalAlignment</font><font style="font-size:11px">=</font><font style="color:blue">&quot;Top&quot;</font><font style="font-size:11px"> </font><font style="color:red">HorizontalAlignment</font><font style="font-size:11px">=</font><font style="color:blue">&quot;Left&quot;</font><font style="font-size:11px">&gt;Button</font><font style="color:blue">&lt;/</font><font style="font-size:11px">Button</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td>    <font style="color:blue">&lt;/</font><font style="font-size:11px">jas:dragCanvas</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)"><font style="color:blue">&lt;/</font><font style="font-size:11px">Grid</font><font style="color:blue">&gt;</font><font style="font-size:11px"> </font></td></tr><tr><td> </td></tr></tbody></table></div><br>Wed, 05 Nov 2008 10:43:10 Z2008-11-05T10:43:10Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#dd6ada00-d47d-4a70-b2aa-7a07610d7975http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#dd6ada00-d47d-4a70-b2aa-7a07610d7975Staratnighthttp://social.msdn.microsoft.com/Profile/en-US/?user=StaratnightLoad XAML File dynamically<div class=quote>I tried this, but I always get an exception:</div><br>I think you got a problem casting from &lt;grid&gt; (your root [Stammebene]) to page. <br><br>Try this:<br> <div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px">Grid </font><font style="color:red">grid</font><font style="font-size:11px"> = (Grid)System.Windows.Markup.XamlReader.Load(xmlReader); </font></td></tr></tbody></table></div><br>Thu, 15 Jan 2009 15:04:26 Z2009-01-15T15:38:47Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#7e1c7643-1ac6-4222-84a2-fe52dcb2ffe1http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a53ff197-8703-4c6c-8726-45570304fb7b#7e1c7643-1ac6-4222-84a2-fe52dcb2ffe1GA30http://social.msdn.microsoft.com/Profile/en-US/?user=GA30Load XAML File dynamically<p>Ashish,</p> <p>Would you please be able to provide a little more detail on how to accomplish 2nd approach: &quot;<span style="font-size:x-small">use a custom page with component, and hook the event handlers via component code&quot;?????<br/><br/>Thank you</span></p>Thu, 04 Jun 2009 00:30:29 Z2009-06-04T00:30:29Z