My existential question about WPF

4 views
Skip to first unread message

Aline Paponaud

unread,
Jun 16, 2008, 4:44:28 PM6/16/08
to wpf-di...@googlegroups.com
Hello everyone,
I am new in this list and am following your interesting conversations. I didn't take the time to send a "hello world" message. Then, it's done.

Well i am really a noob at WPF and, more generally, development. Actually i just finished my studies and started working on a project that uses WPF in my new company. I have a quite good theoretical background (about oo design, and abt the structure and the theory of a IT development project in general). Then, developing with WPF is very complicated for me.
I know Windows forms and have already fulfilled little projects using this technology. Now i feel lost...

So my existential question is:
- Why is there no inheritance possible in graphical terms; i mean if i have a baseclass which is a usercontrol defined in xaml, why can't I create a usercontrol, defined in xaml too, which inherits from it, and use the designer to add some specific controls in my child class for example?
And... Why do i feel so alone with this problem? Is there a "new" way to design user interfaces (using interface implementations instead of inheritance, ...) and why? Was I wrong during my studies doing my little projects and designing my UIs that way (with inheritance everywhere there was something common... It worked well with winforms...)
Don't hesitate to tell me that my question is stupid ;-) but only if you explain me why ;-)

And, to answer the "who are you" subject: my name is Aline, i am a French developer, and will finish my studies (with the end of my internship) the 26th June. and then i will be hired in the company i did my training in.
I am a geek, and a geek girlfriend too. My friends are geeks (Jeremy Alles invited me in this group), my parents are geeks, even my cat is a geek. My sister too, and her boyfriend too.
I love linux and free software, and discovered WPF and the Microsoft world only because it is the most used in companies. (and, unfortunately for my great ideas and for the Free Software Song, i think companies are right... Sorry, RMS)
Except that, I am currently discovering French culture, operas, books, theater, because I actually was geeking during French lessons at school.

That's all!
Thanks in advance for the answers... and hope i am not too ridiculous with it.

Aline



Mike Brown

unread,
Jun 16, 2008, 5:13:54 PM6/16/08
to wpf-di...@googlegroups.com
The big difference with WPF compared to Winforms is that you don't have to use inheritance to modify the Look and Feel of a control. With attached properties, in many cases you don't have to use inheritance to add new behavior to a control.
 
I forget the reason I was told that UserControls can't be extended in WPF, but even if you could, you probably wouldn't want to. I've found that people have gotten a little "is a" crazy when they should be thinking in "has a" terms. It's the classic diamond example when people talk of the "pitfalls" of multiple inheritance. I have a horse and a bird that both inherit from animal. If I add Pegasus to the picture, I have a bird that is a horse or a horse that is a bird. If you look at it a different way...a Pegasus is a Horse that "has" wings, or that can fly, it's not a problem at all. This "pitfall" not a problem with MI per se...it's a problem with using inheritance, when you should use containment.
 
What if you could take the functionality of a bird being able to fly and attach it to a horse...without extending horse? This is what attached properties give in WPF. One example I give on my blog is a GridView that doesn't have sorting out of the box. Instead of inheriting from GridView to make a SortableGridView, you can attach the capability to sort onto the existing GridView.
 
Back to UserControls, there are several solutions to your problem depending on the circumstances. All of them require you to think of WPF from a new perspective. If you can give an example (genericized if need be) of why you feel you need to inherit a usercontrol from another, we can definitely help. Welcome aboard and happy trails!
 
--Mike

Aline Paponaud

unread,
Jun 16, 2008, 5:26:59 PM6/16/08
to wpf-di...@googlegroups.com
Thanks a lot, now I understand...

I think I might read that book that is on my desk, actually, and i will understand this new dependency property huge concept.

Now the thing is: with a very theoretical Object Oriented design (without thinking about what technology or language or framework we are using), i think we cannot use or make the dependency property and "has a"/"is a" choice correctly... The design has to be made in a WPF way. it is a real revolution in the architecture world! Because we will have to think our classes and design, knowing that it will be WPF. (i think we didn't do that before, we were just designing classes using UML or whatever and then, code it, and the program had exactly the same behavior if it is windows forms or java or something else). Maybe it is a little exagerated, but is Microsoft proposing here something very new and, finally, different from a "pure" object-oriented language?

Laurent Bugnion [MVP, MCP]

unread,
Jun 16, 2008, 5:34:42 PM6/16/08
to wpf-di...@googlegroups.com
Salut Aline,

Wow, enfin je peux parler de WPF en français!! Ca fait du bien :)

Bon, on ne va pas ennuyer nos amis ricains plus longtemps? Sorry guys,
back to EN :)

The classic answer to the "Why shouldn't I subclass" answer is Kevin
Moore's post:
http://work.j832.com/2007/06/don-subclass-panel-unless-you-making.html

In short, markup subclassing is bad.

That said, you can subclass in code, for example to add specific
functionality. About this, see my (I hope) classic post:

http://blog.galasoft.ch/archive/2007/03/02/107747.aspx

And yes, like Mike says, most of the time you don't need to because you
can modify the L&F of the element using templates. And also, you can add
your own DependencyProperties to implement new functionality.

Le plus grand challenge avec WPF, c'est de "désapprendre" ce qu'on sait
des technologies "classiques" :)

Bien du plaisir,
Laurent


Aline Paponaud wrote:
> Hello everyone,
> I am new in this list and am following your interesting conversations.
> I didn't take the time to send a "hello world" message. Then, it's done.
>
> Well i am really a noob at WPF and, more generally, development.
> Actually i just finished my studies and started working on a project
> that uses WPF in my new company. I have a quite good theoretical
> background (about oo design, and abt the structure and the theory of a
> IT development project in general). Then, developing with WPF is very
> complicated for me.
> I know Windows forms and have already fulfilled little projects using
> this technology. Now i feel lost...
>
> So my existential question is:

> - Why is there no inheritance possible in /graphical/ terms; i mean if

--
Laurent Bugnion [Microsoft MVP, MCP]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

Laurent Bugnion [MVP, MCP]

unread,
Jun 16, 2008, 5:39:35 PM6/16/08
to wpf-di...@googlegroups.com
Hi again,

While it's true that WPF is very new in many ways, DependencyProperties
(DPs) are actually a "has" relationship between objects, but with
something more. The WPF property system adds much functionality (such as
a built-in controller to help you realize a MVC pattern), but you can
actually inherit DependencyObjects to represent your datas in an UML
way. Note that there was a long discussion in this group about using DOs
and DPs versus using "normal" CLR objects and something called
INotifyPropertyChanged. Check the group's archive and you'll find it.

Where do you live? I am in Zurich, though I was born in Lausanne.

Friendly,
Laurent

--

Sacha Barber

unread,
Jun 17, 2008, 4:19:58 AM6/17/08
to wpf-di...@googlegroups.com
Actually you can inherit a usercontrol from another usercontrol in WPF I do just that.

Check the attached out

What is NOT possible is to use a wplit XAML/Cs class that inherits from another split XAML/CS class. This is a shortfall with the current version of WPF and the designers.


This is described in this post


http://forums.msdn.microsoft.com/en-US/wpf/thread/80eb3f57-9907-4bf7-9f48-b75043b8c97b/

Pay close attention to the comment from Marco Zhou


Laurent also has a nice post about inheriting from a custom Window. check out

http://geekswithblogs.net/lbugnion/archive/2007/03/02/107747.aspx









Date: Mon, 16 Jun 2008 22:44:28 +0200
From: boo...@gmail.com
To: wpf-di...@googlegroups.com
Subject: My existential question about WPF
ucEncoreMain.cs
ucWizardPanelBase.xaml.cs
ucWizardPanelBase.xaml
Reply all
Reply to author
Forward
0 new messages