Question

I have several similar user controls which display listviews of respectively different data entities. In the code-behind files of these controls there is quite a bit of common business logic.

How can these common methods be combined in a single "super-class" as I would do in a normal non-wpf-case (reusing any xaml parts isnt necessary)? Creating a super-control (with just a skeleton xaml file) which the controls inherit from gives a parser error of:

Partial declarations of DERIVED-CLASS must not specify different base classes

in the derived user controls.

Thank you a lot.

Was it helpful?

Solution

How did you use the "super-control" in the derived user controls? Simply change the base class?

If so, you need to change the root element of your XAML file (i.e. the one on which x:Class is specified) to match.

OTHER TIPS

Sounds like DataTemplating is what you want. You set up a general custom list view that contains all your business logic and then use data templating in the XAML to customise the view depending on the type of object that it contains.

Here is a great link to get you started: http://msdn.microsoft.com/en-us/library/ms742521.aspx

My best suggestion is to make lookless controls (controls w/ no XAML associated). These you can inherit and ultimately more powerful because the styles you can make will be more flexible (ie Button you can style into anything. A button is a lookless control). Your default style for the control can be placed in the Themes\generic.xaml, and you can make other default styles for subclassed controls. These styles can have copies that exist in other resource dicts also.

I cover lookless controls here on my blog post, but it is geared towards silverlight. It's slightly different syntactically in WPF, but same ideas.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top