Wednesday, March 16, 2011

I am not receiving Clicks in the blank area of a StackPanel

I created a panel with two controls in it: textblock and image. But the panel only accepts clicks or mouse over the text and the image but any blank area around them in the panel is ignored.

Solution: change your panel's background to Transparent. This way you will keep your panel transparent and force receiving mouse events on your panel.

WPF: define attached property or dependency property

When to define dependency property and when to define attached property.

- Define attached property, if you want to give your user the ability to default this property to a control and to all of its descendents as well.
- Define attached property, when you want all different kinds of controls to have the capability to carry this property with them. May be because they could be children of your control/panel so you give them the ability to assign this property so they can participate in deciding how to be laid in your panel.

WPF: User Control vs Custom Control

When to use User Control and when to use Custom Control. Simply:

Use Custom Control if:
- If you want to override a control to expand its functionality or restrict it, like TextBox or Button
- If you want your clients to be able to create different ControlTemplate for your control.

Use User Control if
- you want to create a composite of controls to give group of functionality all together.