So I am working on a new app and I am using Expression Blend (for the first time) to create the layout and styles etc. but I have a question about when I would want to create a user control.
I have a borer that I want to use as the background for lots of stuff, however it is really a border in a border - then we will drop whatever controls into it. I want to reuse this of course, what is the best way to do that. I am thinking I want to make it into a user control?
The problem is unlike a standard border - I can't just edit a style in a resource dictionary because like I said - it's a border in a border.
Thanks in advance.
You'd probably be better off not making a
UserControl
and instead making a Custom Control that derives fromContentControl
or something similar - I say this because you're planning on having it contain other controls and that's a lot easier to do with Custom Controls thanUserControl
s.Here is a UserControl example that allows for UIElement content:
Usage example:
Looks like:
Just modify the borders at will.
Edit: To actually answer the question and somewhat reiterate what i said in a comment to Tim's answer, UserControls are appropriate for this since they directly encapsulate the visual representation and allow for composition while not requiring much custom logic (in theory they can be very complex though and include a lot of logic). They are more lightweight and immediate than CustomControls.
In WPF controls (i.e. normal controls, including CustomControls which just inherit from them) are considered to be lookless, they normally provide a default template but their key aspect is their functionality, if you think of a
ComboBox
for example, it's a control which contains items, it should have one or no selected element and there should be a dropdown which displays the items and supports selection etc. It is the responsibility of the control to provide the necessary properties and methods which make up this functionality. Since this sometimes requires certain visual elements to exist controls can define parts which represent the minimal interface to the front-end.Have a look at the Control Authoring overview, it is more in-depth and probably explains a lot of things better than i can.
Also: The ultimate lightweight method is only using Templates:
This yields the same result as the UserControl.