Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheriting from a UserControl in WPF

I am fairly new to WPF and I am having a problem with inheriting from a user control.

I created a User Control and now I need to inherit from that control and add some more functionality.

Has anyone does this sort of thing before? Any help would be greatly appreciated.

Thank you

like image 581
user35129 Avatar asked Nov 06 '08 15:11

user35129


1 Answers

Well .. you create your base control

public abstract class BaseUserControl : UserControl{...} 

then in the XAML file :

<Controls:BaseUserControl x:Class="Termo.Win.Controls.ChildControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="clr-namespace:Namespace.Of.Your.BaseControl"> 

And that should work.

EDIT: Hmm.. this example is useful when you have a base control without XAML and then inherit from it. The other way around(from a base control with Xaml) - I'm not sure how you can go about it.

EDIT2: Apparently from this post + comments i take that what you want might not be possible.

like image 79
sirrocco Avatar answered Oct 04 '22 22:10

sirrocco