Page view counter
Inheritance limitation (FrameworkElement & DependencyObject) Subscribe to this thread
Last post 04-11-2009 5:26 AM by joji777. 19 replies.
Sort Posts:
04-05-2008 4:15 PM
Inheritance limitation (FrameworkElement & DependencyObject)

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...

PatriceVB

Loading...
Joined on 04-05-2008
Posts 3
04-05-2008 11:38 PM
Re: Inheritance limitation (FrameworkElement & DependencyObject)

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.

Sopheap Ly
Prime Inventor
http://www.SilverlightExamples.net - Silverlight Tutorials and Examples

Sopheap Ly

Loading...
Joined on 01-03-2008
Phnom Penh, Mars.
Posts 205
04-06-2008 4:10 AM
Re: Inheritance limitation (FrameworkElement & DependencyObject)

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...

PatriceVB

Loading...
Joined on 04-05-2008
Posts 3
04-21-2008 1:19 PM
Re: Inheritance limitation (FrameworkElement & DependencyObject)

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.

Eric Willeke

Loading...
Joined on 04-15-2008
Indianapolis, IN
Posts 26
04-21-2008 1:53 PM
Re: Re: Inheritance limitation (FrameworkElement & DependencyObject)

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.
 

Jabb

Loading...
Joined on 03-06-2008
Posts 81
05-21-2008 4:27 PM
Re: Re: Inheritance limitation (FrameworkElement & DependencyObject)

I want to cast my vote for removing the limitation as well.

tonypujals

Loading...
Joined on 04-13-2008
Posts 5
05-27-2008 4:36 PM
Re: Re: Inheritance limitation (FrameworkElement & DependencyObject)

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.

Dave Relyea [MSFT]
http://blogs.msdn.com/devdave

Dave Relyea

Loading...
Joined on 05-09-2007
Posts 249
05-27-2008 4:59 PM
Re: Re: Inheritance limitation (FrameworkElement & DependencyObject)

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.

 

Eric Willeke

Loading...
Joined on 04-15-2008
Indianapolis, IN
Posts 26
05-27-2008 5:07 PM
Re: Re: Inheritance limitation (FrameworkElement & DependencyObject)

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 :)

PatriceVB

Loading...
Joined on 04-05-2008
Posts 3
06-06-2008 2:36 AM
Re: Re: Inheritance limitation (FrameworkElement & DependencyObject)

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.

Kevmeister

Loading...
Joined on 04-30-2008
Posts 117
06-09-2008 4:27 PM
Re: Re: Inheritance limitation (FrameworkElement & DependencyObject)

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

xiard

Loading...
Joined on 06-09-2008
Posts 45
07-25-2008 11:11 AM
Re: Inheritance limitation (FrameworkElement & DependencyObject)

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.

asterite

Loading...
Joined on 07-15-2008
Posts 3
09-11-2008 7:36 PM
Re: Inheritance limitation (FrameworkElement & DependencyObject)

 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:

  1. Just create a class (not inheriting). This has the downside of not being able to use FindName on the object and modify it at runtime.
  2. Inherit from control. This confuses the developer because he gets a zillion properties that have absolutely no effect.
Both options are really poor solutions for a good API.
Odegaard

Loading...
Joined on 06-26-2003
California, USA
Posts 47
03-28-2009 9:33 AM
Re: Inheritance limitation (FrameworkElement & DependencyObject)

Is this allowed in SL3 now??

avbersSL

Loading...
Joined on 08-10-2008
The Netherlands
Posts 71
03-28-2009 1:09 PM
Re: Inheritance limitation (FrameworkElement & DependencyObject)
It was an SL2 beta issue, and has been possible since Silverlight 2RTW.

--
/Morten | blog - twitter
Please click on "Mark as Answer" if this answered your question.

SharpGIS

Loading...
Joined on 02-18-2009
Redlands, CA
Posts 502
04-10-2009 8:44 PM
Re: Inheritance limitation (FrameworkElement & DependencyObject)

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.

joji777

Loading...
Joined on 09-28-2007
Posts 181
04-10-2009 9:27 PM
Re: Re: Inheritance limitation (FrameworkElement & DependencyObject)
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.

--
/Morten | blog - twitter
Please click on "Mark as Answer" if this answered your question.

SharpGIS

Loading...
Joined on 02-18-2009
Redlands, CA
Posts 502
04-10-2009 9:40 PM
Re: Re: Inheritance limitation (FrameworkElement & DependencyObject)

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

private static Page page = new Page();
page.Dispatcher.BeginInvoke(new Action(() =>
{
var textBlock = page.mygrid
.FindName("uploading_grid_textblok_1") as TextBlock;
textBlock.Text =
string.Empty;
textBlock.Text += statusstring;
}));

This does not work, I tried all possible ways, and it does not work, now i am working on another way which works partialy but still not reliable. Above mentioned code will give you different errors on different changes.

 

joji777

Loading...
Joined on 09-28-2007
Posts 181
04-10-2009 10:07 PM
Re: Re: Re: Inheritance limitation (FrameworkElement & DependencyObject)
Errrrr and that has what to do with the DepedencyObject constructor was internal at the beta release (ie. can't inherit from it) ?

--
/Morten | blog - twitter
Please click on "Mark as Answer" if this answered your question.

SharpGIS

Loading...
Joined on 02-18-2009
Redlands, CA
Posts 502
04-11-2009 5:26 AM
Re: Re: Re: Inheritance limitation (FrameworkElement & DependencyObject)

Hi,

See "odegaard" post of this date

09-11-2008 7:36 PM
 
in my post, in given code,,,, checck page.Dispathcer..................
joji777

Loading...
Joined on 09-28-2007
Posts 181
Microsoft Communities