When do I derive from UIElement
and FrameworkElement
considering FrameworkElement
inherits UIElement
. Can anyone give real life examples?
相关问题
- VNC control for WPF application
- WPF Binding from System.Windows.SystemParameters.P
- how to Enumerate local fonts in silverlight 4
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
I don't have any examples right now, but I can refer you to links that might help.
UIElement is a base class for most of the objects that have visual appearance and can process basic input in Silverlight.
FrameworkElement provides a framework of common APIs for objects that participate in Silverlight layout. FrameworkElement also defines APIs related to data binding, object tree, and object lifetime feature areas in Silverlight.
So what additional capabilities do you get? See http://forums.silverlight.net/p/205863/482651.aspx
This is a good page for learning about WPF Architecture, and this answer only applies to WPF. Check out the
UIElement
andFrameworkElement
sections, as well as the rest if you have time. Here's a quote from the linked page explaining why the 2 levels exist:In short,
UIElement
s know how to draw themselves (because they are derived from Visual). They can also use the routed events system by providing virtual methods likeOnPreviewMouseDown
andOnMouseDown
, and part of the layout system by implementingMeasure
andArrange
.FrameworkElement
s extend the layout system by implementing some of the virtual methods defined inUIElement
. They provide a consistent way of setting layout properties, e.g. theMargin
property and theMinWidth
property. Additionally, the can be styled, and they can take part in data binding.In answer to your question, if you need any of the extra abilities that
FrameworkElement
add, e.g. you need styles, binding or a layout system that's easier to use, then derive from them. Otherwise, derive fromUIElement
as there is a slight overhead from usingFrameworkElement
.Also, you should have a look at the
Control
class (derived fromFrameworkElement
), as these provide useful new layers of functionality like Templating and properties likePadding
.Familiarising yourself with the inheritance hierarchy is also a good idea, you might want to derive from other classes in it (though probably no higher up the chain than
Visual
).