locked
Deriving class button possible but not class border.. why? RRS feed

  • Question

  • hi i ve written an app with a class which derives the class Button, now where i added drag and drop functions, i think a class with a mousedown eventhandler would b more useful..

    so i decided to switch to class border, which would b not much visual difference to the button it was before..(thats why i wanted to switch to border)

    the class border is not derivable, but why? and can i do it anyhow ?

    Wednesday, October 8, 2008 2:40 AM

Answers

  • Hi,

    the class border is not derivable, but why? and can i do it anyhow ?

    That's because the Border object is sealed, it cannot be inherited.

    You can try to create the style template of the Bolder in the app.xaml to make the bolder to be much visual difference.

    Friday, October 10, 2008 4:00 AM
  • When creating managed classes, we had to decide whether or not to make them sealed or not. Discussing this subject can lead to a religious debate, so let me just point out that pragmatism was a major factor in deciding to let Button be subclassed, but not Border, for example. Some of the questions we asked were:

    • How much value can subclassing a type actually provide?
    • Do we have the resources to make sure that subclassed types work properly?

    In the case of Border, the answer to the first question is "not much". You can add orthogonal functionality but you can't really change the essential nature of Border, so we don't want to spend any resources on making sure that subclassing Border works.

    In your case, you can probably get what you want by making a UserControl with a Border as its only child.

    Sunday, October 12, 2008 11:34 AM

All replies

  • Hi,

    the class border is not derivable, but why? and can i do it anyhow ?

    That's because the Border object is sealed, it cannot be inherited.

    You can try to create the style template of the Bolder in the app.xaml to make the bolder to be much visual difference.

    Friday, October 10, 2008 4:00 AM
  •  

    hallo amanda, the problem is not about visual stuff, i built a quite big class which i wanted to derive from border just to get the visual part shown but still have all functions in background

    like this way --  myclass : Border

    but exactly that is impossible

    Friday, October 10, 2008 4:12 AM
  • When creating managed classes, we had to decide whether or not to make them sealed or not. Discussing this subject can lead to a religious debate, so let me just point out that pragmatism was a major factor in deciding to let Button be subclassed, but not Border, for example. Some of the questions we asked were:

    • How much value can subclassing a type actually provide?
    • Do we have the resources to make sure that subclassed types work properly?

    In the case of Border, the answer to the first question is "not much". You can add orthogonal functionality but you can't really change the essential nature of Border, so we don't want to spend any resources on making sure that subclassing Border works.

    In your case, you can probably get what you want by making a UserControl with a Border as its only child.

    Sunday, October 12, 2008 11:34 AM
  •  

    thank u for the statement dave

     

    well the point why i changed to border is:

    buttons dont have a working mouseleftbuttondown handler, and without that drag and drop (how people know it) is quite impossible.

    will that be fixed within the next few months?

    greetings

    silverstarter

    edit: a usercontrol doesnt have a child or children property, atm. im trying it with a grid

     

    Monday, October 13, 2008 2:13 AM