469,612 Members | 1,621 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,612 developers. It's quick & easy.

XAMLReader for external xaml files and event handling

I have a sample XAML file:

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Button Name="button2" Height="23" Width="300" Margin="31,37,0,0"
Click="doit">Hello World</Button>

If I compile the application normally, the XAML is converted to a .cs and
then an application is built: on clicking the button "doit" gets called if it
is code-behind or is embedded in an <x:codeblock within the XAML itself.
The problem arises when I try to load XAML files on the fly at runtime, using
StreamReader and XamlReader:-
//Load file1.xaml
StreamReader sr = new StreamReader("file1.xaml");
DependencyObject rootElement =
XamlReader.Load(sr.BaseStream) as DependencyObject;

XamlReader throws an exception with a message "Must compile XAML file that
specifies events"

This happens when the event is either code-behind or inline in an <x:code>
tag within the XAML itself.

I would really like the flexibilty of being able to generate code on the fly
without having to re-compile my application (even though I will take a hit on

Does anyone know how I can loadruntime XAML files which have event calls?


Sep 21 '07 #1
0 5429

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Thilaka | last post: by
6 posts views Thread by moondaddy | last post: by
3 posts views Thread by arunonw3 | last post: by
3 posts views Thread by onno.willems | last post: by
1 post views Thread by DeanB | last post: by
reply views Thread by aagranov2007 | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.