This is a mirror of official site: http://jasper-net.blogspot.com/

Subclassing Silverlight Controls

| Monday, November 1, 2010
While I think everyone understands that fact that you can subclass Silverlight controls in code, I think the concept of subclassing code + xaml is less well understood.

First off, why would you want to subclass code + xaml? In most cases, you don’t need to.  This is really more of an edge case scenerio.  I have a control which is a Subclassed treeview.  These treeview needs a number of Hierarchical data templates that work together to make the tree work.  These are defined in xaml and I would like to re-use them, not to mention some Code-Behind that makes the tree do things like drag and drop.  

Now, I could of course do the same thing in code but I also have some binding and other things in the xaml that already works and I would like to re-use the same binding and everything else.  So what do I do?

Here is the trick: Create a new UserControl.  Then change the base type from Usercontrol to whatever the type is that you want to subclass.  Change the subclass in the codebehind as well.  You can now drop this into other pages or UserControls multiple times.  Suddenly you have reused your XAML!

Read more: SilverlightDev.net

Posted via email from .NET Info

0 comments: