By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,504 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,504 IT Pros & Developers. It's quick & easy.

XAMLReader for external xaml files and event handling

P: n/a
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>
</StackPanel>

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
performance).

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

Thanks


Sep 21 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.