CAB & WPF (Avalon)


Of course the question of how CAB works with WPF (Avalon) is one we hear frequently. After all this a new technology that will be soon available and it's just fair to be concerned on investments happening today and how will they play in the future.


Microsoft is investing in having a good interop story around this and our team has been in close contact with Avalon & Winforms architects all throughout CAB development.


So last week after Expression CTP, I installed it in my box and played around fro a couple of hours and have my first WorkItemExtension hosting an Avalon control (a ListBox) and it is very straight forward. I just followed the CTP instructions for Winforms/Avalon interop:



I copied the code from the CustomerWorkItemExtension example in the BankTeller QuickStart and then I created a UserControl (and SmartPart) with a Winforms Panel in it. In the constructor for the control I added the following statements and voila:



ElementHost host = new ElementHost();

System.Windows.Controls.ListBox ctrl = new System.Windows.Controls.ListBox();

for (int i = 0; i < 10; i++ ) { ctrl.Items.Add("Item " + i.ToString()); }

host.Dock = DockStyle.Fill;

host.Controls.Add(ctrl);

this.panel1.Controls.Add(host);


ElementHost is the key interop class. I'm far from being a Designer so I just used plain, vanilla, non sexy UI. Actually the ListBox is indistinguishable from a common Winforms Listbox, but it is coming from a different assembly. I'm modifying the control to host any XAML described UI part now wo you can really tell it is an Avalon part.


 

Comments (2)
  1. I’m starting a new project where we will be using Windows Presentation Foundation (WPF) . I’ve done very

Comments are closed.

Skip to main content