ChrisAn's Blog Please read my disclaimer.

simplegeek

a.k.a. Chris Anderson

Quick disections of Windows Forms in XAML

Just to make sure everyone understands the last post I did, I thought I'd simplify a bit and explain what everything is... First, a warning: when working on this post I ran into a lot of cases where XamlPad would hang or crash. Not sure the cause, I'll work on debugging this tomorrow. For now, I would suggest editing in notepad and pasting into XamlPad. My guess is that there is something about tearing down and recreating the Windows Forms controls that is causing a hang...

<?Mapping
  XmlNamespace="windowsforms"
  ClrNamespace="System.Windows.Forms"
  Assembly="System.Windows.Forms" ?>
<?Mapping
  XmlNamespace="windowsformsintegration"
  ClrNamespace="System.Windows.Forms.Integration"
  Assembly="WindowsFormsIntegration" ?>

<Grid
xmlns="http://schemas.microsoft.com/2003/xaml"
xmlns:x="Definition" xmlns:wf="windowsforms"
xmlns:wfi="windowsformsintegration">

<wfi:WindowsFormsHost>
   <wf:Button Text="Hello From Windows Forms" />
</wfi:WindowsFormsHost>

</Grid>

Anyway, the first two tags are "mapping PIs". These will be going away in a future rev of the XAML spec, but for now they are the way to import a namespace/assembly into an XML namespace. We need to import System.Windows.Forms and (because XamlPad is written in Avalon) the System.Windows.Forms.Integration namespace. SWF.Integration is there when you need to host Avalon in Windows Forms or vice versa.

The root tag is a Grid, really it could be about any Avalon element. Then we have the WindowsFormsHost, which is an Avalon element that knows how to host a Windows Forms control. Finally we have the Windows Forms Button tag, with it's text set. Really the only whacky part is the mapping PIs.

11/22/2004 8:38 PM | #WinFX #Software

Content © 2003 Chris Anderson | Subscribe to my RSS feed.

Powered by BlogX