How to inherit from a UserControl in WPF / NET 3.0?

Hello everyone,

I′ve an importend question, because I can′t inherit an created UserControl under NET 3.0. It′s an WindowsApplication WPF Project and I tried to inherit likes the well known rules in NET 2.0:

public class NewUserControl : BaseUserControl

I′ve seen some code examples which contained some instructions about "VisualInheritance" with XAML. But this isn′t enough, becaus I must inherit the whole class with it′s code.

But it doesn′t work anymore, I get some compiler errors - who can help me out? (It′s very urgent)

Thanks a lot for reading and your help

[1067 byte] By [CongoFX] at [2008-1-7]
# 1
hi,

what is the compiler warning?

regards

MarlonGrech at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2

Hello Marlon,

thank you very much for your quit answer.

The compiler error displays:

"Partial declarations of must not specify different base classes"

It seems that there are partial classes created by visual studio, when adding a user control to the project. But I′ve tried very hard to find this partial class, I can′t find it.

There are not any results by google, can′t find anything about this problem...

Any ideas?

CongoFX at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3

Hi there,

The problem is that since you created a new user control from the Visual studio it will automatically create a class that inherits from UserControl.

Visual studio creates a hiden class (filed under obj\Debug\) called classname.g.cs. This usual inherits from user control...
to navigate to this file just right click on your class and select Go to Defenition . This should take you to the hidden class..

hope this helps, get back to me if you need anything else

regards

MarlonGrech at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4

As far as I know, this means that the .xaml file's class declaration doesn't match the class name in the code-behind file. You shouldn't have to touch the generated file (the *.g.cs), only your .xaml and .cs files. Make sure that the "x:Class=MyNamespace.MyClass" matches the namespace and classname of the .cs file. After you make your changes, you may have to do a Build|Clean, Build|Rebuild to ensure that the *.g.cs file gets properly updated.

I found this to be a good article on the subject: http://geekswithblogs.net/lbugnion/archive/2007/03/02/107747.aspx.

Tor Langlo

Koda Software

Web: http://www.kodasoftware.com

Blog: http://torlanglo.spaces.live.com

TorLanglo at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified