Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You will not be able to produce a class that works in the same way because Silverlight does not support the creation of custom elements that derive from the <code>Shape</code> base class.</p> <p>The reason it's impossible to create a custom shape in Silveright is that Silverlight does not share WPF's "visual layer". If you want to understand fully why what you're trying is impossible, you need to understand how Silverlight is very different from WPF here. (And if you don't care, skip the next 2 paragraphs.)</p> <p>In WPF, you can work at two completely different levels: the visual layer, or the framework layer. The visual layer's services are provided by WindowsBase.dll and PresentationCore.dll. This provides basic rendering and input services. But if you want things like styling, data binding, layout, templating and so on, you need the framework services, and these are provided by PresentationFramework.dll. The shape types - <code>Rectangle</code>, <code>Path</code>, and so on - are all framework types - they derive from <code>FrameworkElement</code> and they support data binding, layout, animation and so on. But they are implemented on top of the visual layer - if you look at any of the <code>Shape</code> types in Reflector or ILDASM you'll see they all override the <code>OnRender</code> method, and that's where the code that defines the actual shape lives. (<code>OnRender</code> is a visual layer function.) And because the visual layer is a fully supported and documented API, you're free to write your own shapes in WPF - you can write exactly the same sort of code as you'll find in the built-in shape classes.</p> <p>Silverlight doesn't make this visual/framework distinction - in Silverlight, WPF's visual layer has essentially collapsed into the framework layer. So if you look at the shape types in Reflector or ILDASM, you'll see that they contain no <code>OnRender</code> method, and they're almost empty. That's because in Silverlight, the shapes are all intrinsics - the plugin has built-in special handling for <code>Ellipse</code>, <code>Path</code>, and all the other shapes. So the set of shapes is not open to extension in Silverilght. There is no <code>OnRender</code> method to override in Silverlight. So you simply cannot write your own custom class that derives from <code>Shape</code> in Silverlight.</p> <p>So, either a custom <code>Control</code> or a <code>UserControl</code> will be the way to go, I'm afraid. This shouldn't stop the <code>MouseEnter</code> and <code>MouseLeave</code> from working though. Have you actually found that those don't work? Or are you just assuming that they won't work?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload