Sunday, July 08, 2007

Flow Documents and Code Behind

It is possible to have XAML controls with event handlers in a Flow Document. This can be accomplished using Visual studio 2005 by:

  • Add a FlowDocument (WPF) to a Visual Studio 2005 .NET 3.0 WPF project (i.e. FlowDocument2.xaml)
  • Add a class to the project named FlowDocument2.xaml.vb (VS 2005 does not automatically add an associated "code-behind" class)
  • In FlowDocument2.xaml in the <FlowDocument> element add the attribute: <FlowDocument a:Class="FlowDocument2" ....
  • Within a <Paragraph> element add:
    Test Text<InlineUIContainer><Button Name="TestCmd" Content="Press Me"></Button></InlineUIContainer>Test Text
  • Build the project
  • In the Code-behind class (FlowDocument2.xaml.vb) for TestCmd (the button) add a click event
  • In the click event place some code (i.e. MessageBox.Show("clicked")
  • Make FlowDocument2.xaml the startup URI for the project
  • Run the project (F5 or <Shift>F5

Labels:

1 Comments:

At 11:49 PM, Blogger Sharath said...

Hi,
I tried this and It didn't work.
I am getting an exeception

'Class' attribute does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml' namespace.

Please help me out.

Regards
Sharath M

 

Post a Comment

<< Home