ChrisAn's Blog Please read my disclaimer.

simplegeek

a.k.a. Chris Anderson

Windows Forms and XAML

Oh yes, it works!

Avalon, XAML, and Windows Forms

Using any rev of XamlPad, you can paste the following XAML into the window and see Avalon and Windows Forms components interoperability. Wahoo! I added a new snippet to XamlPad rev 8 that is this sample. If you have a current version of XamlPad, just delete the snippets.xml file from your My Documents\XamlPad directory and XamlPad will automatically recreate the file. I should probably add a feature to recreate this file. Check this out:

<?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">

<Grid>
 <Grid.ColumnDefinitions>
  <ColumnDefinition Width="*" />
  <ColumnDefinition Width="*" />
 </Grid.ColumnDefinitions>
 <Grid.RowDefinitions>
  <RowDefinition Height="*" />
  <RowDefinition Height="*" />
 </Grid.RowDefinitions>
  <Button Grid.Row="1">Hello From Avalon</Button>
  <Canvas Grid.Column="1" >
  <Ellipse Width="50" Height="50">
   <Canvas.Top><LengthAnimation From="0" To="100" Duration="8" AutoReverse="True" RepeatDuration="Indefinite" /></Canvas.Top>
   <Canvas.Left><LengthAnimation From="0" To="200" Duration="2" AutoReverse="True" RepeatDuration="Indefinite" /></Canvas.Left>
   <Ellipse.Fill>
<LinearGradientBrush><LinearGradientBrush.GradientStops><GradientStop Offset="0" Color="#FFFFFFFF" /><GradientStop Offset=".33" Color="#FFFF0000" /><GradientStop Offset=".66" Color="#FF00FF00" /><GradientStop Offset="1" Color="#FF0000FF" /></LinearGradientBrush.GradientStops></LinearGradientBrush>
   </Ellipse.Fill>
  </Ellipse>
 </Canvas>
  <wfi:WindowsFormsHost Grid.Row="1" Grid.Column="1">
   <wf:Button Text="Hello From Windows Forms" />
  </wfi:WindowsFormsHost>
  <wfi:WindowsFormsHost>
   <wf:TreeView>
    <wf:TreeView.Nodes>
      <wf:TreeNode Text="Hello">
        <wf:TreeNode.Nodes>
          <wf:TreeNode Text="Hello" />
          <wf:TreeNode Text="Hello" />
          <wf:TreeNode Text="Hello" />
          <wf:TreeNode Text="Hello" />
        </wf:TreeNode.Nodes>
      </wf:TreeNode>
      <wf:TreeNode Text="Hello" />
      <wf:TreeNode Text="Hello" />
      <wf:TreeNode Text="Hello" />
      <wf:TreeNode Text="Hello" />
    </wf:TreeView.Nodes>
    
   </wf:TreeView>
  </wfi:WindowsFormsHost>
</Grid>

</Grid>

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

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

Powered by BlogX