Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Inheritance limitation (FrameworkElement & DependencyObject)
19 replies. Latest Post by joji777 on April 11, 2009.
(0)
PatriceVB
Member
4 points
3 Posts
04-05-2008 4:15 PM |
Why does Silverlight 2 prevents developers to create classes that inherits from FrameworkElement or DependencyObject ?
I really does not understand this design that prevents developers to implement dependency properties in their own classes except by inheriting from the Control class.
I think that it is a major limitation of the framework...
Sopheap Ly
Participant
902 points
205 Posts
04-05-2008 11:38 PM |
Control class is FrameworkElement and more. As far as I know, a class that inherits from Control can do everything that a subclass of FrameworkElement does, and then some.
I guess Silverlight team doesn't want to you branch off a totally different controls set that are incompatible with everyone else's.
04-06-2008 4:10 AM |
Well, that does't answer my question... It should not be necessary to inherits from the Control class to be able to use and implement dependency properties. IfI want to create a technical class that is NOT a control, I currently have to define it as a control while it's not the case. In WPF and in WF we are able to inherits directly from dependencyobjet, frameworkelement and uielement and we do this quite often.
This is one of the basic stuff you can do that is unfortunately not supported by Silverlight and I would like to understand why...
Eric Wil...
34 points
26 Posts
04-21-2008 1:19 PM |
I'd like to add a vote that this is a problem.
There's frequently need to create an object that can participate in the binding behavior without being a part of anything else, and certainly without having any visuals associated with it. I'm currently forced to make it a Control, or take the road less traveled and call it a "FrameworkTemplate" as this seems to be the lightest-weight class that derives from DependencyObject and also provides a protected constructor.
Regardless, it is nice to have very light-weight DependencyObject derived objects, and that's not currently possible.
Jabb
462 points
81 Posts
04-21-2008 1:53 PM |
This may be because it's Beta 1 - hopefully this problem will be resolved in Beta 2.
I agree, we really should be able to subclass from DependencyObject.
tonypujals
10 points
5 Posts
05-21-2008 4:27 PM |
I want to cast my vote for removing the limitation as well.
Dave Relyea
1084 points
249 Posts
05-27-2008 4:36 PM |
What sorts of things do you want to do with your subclasses? Note that subclassing FrameworkElement is not all that useful, because we don't support low-level drawing primitives, so you have to encapsulate other elements.
05-27-2008 4:59 PM |
The biggest thing I've wanted to do was to define a data object that can host Dependency Properties that can then easily participate in data binding. The specific design case isn't the strongest currently, but it's a pattern that I've used consistently in WPF applications to great effect. As it stands, I'm approximating it through post-construction assignment.
Having dug into it more than I had when I originally posted this comment, I'm not entirely sure the current data binding support handles the cases that I was attempting to pursue anyway, but in the long run this would be useful.
Clarification, I was attempting to subclass DependencyObject, not FrameworkElement. Also, making OnPropertyChanged "internal protected virtual" would open up a lot of the event handling and abstraction I was also hoping to accomplish with using DependencyObject.
05-27-2008 5:07 PM |
Common Guy! You may be right about the frameworkelement but what about the DependencyObject but do you think that it is normal to have to inherit from the control class to be able to implement dependency properties? We should at least be able to inherits from dependency objects to gain the ability to use the features provided by Silverlight like the animations without having to create a control for that like what we can do in WPF :)
Kevmeister
249 points
119 Posts
06-06-2008 2:36 AM |
I have only just run into this problem myself (wanting to derive from DependencyObject, to use the dependency properties system).
I also vote that it should be possible to derive from DependencyObject.
xiard
75 points
45 Posts
06-09-2008 4:27 PM |
I'll go ahead and add my vote as well to allow inheritance from DependencyObject a la WPF. I'm trying to create a custom class that will be used in an IEnumerable to bind to a DataGrid. The columns of the DataGrid would bind to the DependencyProperties I create in this custom class. Essentially, the custom DependencyObject subclass would be the DataContext of the items bound via the DataGrid ItemsSource property. Since I would obviously have one instance of my custom class per row in the DataGrid, I want the rows to be as light-weight as possible. I'm going to go ahead and derive my subclass from Control and see how far I get, but I certainly was surprised to find out that I couldn't derive from DependencyObject.
Thanks,
David Cater
asterite
07-25-2008 11:11 AM |
I want to add my vote for this. I need to do an animation on one of my objects, which is *not* visible in the UI. This object implements INotifyPropertyChanged and listeners are registered to that which do update the UI. I really can't understand why DependencyObject can't be subclassed by us.
Odegaard
35 points
48 Posts
09-11-2008 7:36 PM |
I'll cast a vote as well !
I'm currently working on an API and there are sooo many cases where i'd like to use dependency object.
Right now I have two options:
avbersSL
164 points
77 Posts
03-28-2009 9:33 AM |
Is this allowed in SL3 now??
SharpGIS
Contributor
3397 points
611 Posts
03-28-2009 1:09 PM |
It was an SL2 beta issue, and has been possible since Silverlight 2RTW.
joji777
80 points
213 Posts
04-10-2009 8:44 PM |
I am also badly stuck because of this problem, and so far I spent more than 3 days tpo find a solution and unable to find one. I am in great favor to finish this limitation and inheritance should be allowed.
04-10-2009 9:27 PM |
How can this be a limitation for you, when this limitation has been removed since SL2 was released in its final state? This is an old beta issue.
04-10-2009 9:40 PM |
Well I am using SL2 and it is not working. I can see at front of my eyes. What I am trying to do its,
I have a Page class, then I created another class which has method to create a button and on that button click you select a file to upload on my server, all this functionality in my Uploader class, this also update the progress of uploading. This Uploader class has 2 public methods, one creates button and other creates a text block (its text i want to update to show progress.)
I call this create button and create text method in Page by creating instance of Uploader class in a for loop and create 4 buttons and text blocks for each button. Now in uploader class i have to write following code
04-10-2009 10:07 PM |
Errrrr and that has what to do with the DepedencyObject constructor was internal at the beta release (ie. can't inherit from it) ?
04-11-2009 5:26 AM |
Hi,
See "odegaard" post of this date