Question

I need to create a basic user control with certain functionality (like dragging, minimizing and more..). Now I need a bunch of other user controls to inherit from it and add their content.

I want an option to add new user controls that implements only a part of the base control and remains with the rest of the elements and functionality.

How can I bind a certain element (grid, stackpanael,.. whatever..) from the base user control to the new control? (without loading xaml in the code behind)

I basically want to "plant" a xaml element in a dedicated element on the base user control from a different user control.

Was it helpful?

Solution

If you write a custom control, one of the Controls you can use in the template is called a "ContentControl." Then when you use the Custom Control on a page, you can specify in xaml what the content is going to be. Thus you can put in a Grid, StackPanel, whatever in there.

But note that writing your own Custom Control is rarely done other than by 3rd party component vendors, as it requires a fairly deep knowledge of SL (for example, how to use Dependancy Properties). More commonly used is the "User Control" which is far easier to use and requires no such knowledge. I usually start by trying to accomplish what I need with a UserControl, and if I hit a roadblock, then switch over to a CustomControl.

But most of the existing controls already come with the functionality you describe - drag and drop, minimize etc. SL has a rich UI control set already, so a good place to start is by seeing if one of the existing controls has most of what you need, and then take it from there.

Greg

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