views:

144

answers:

2

Hi all,

I have started writing some custom controls for a highly visual project. I was wondering what are your 'best practices' when coding WPF custom controls?

Thanks,

Adam

+1  A: 

Keep property names the same as the property names for built-in Controls if you can do so without changing their meaning.

e.g. if you have a CustomerDisplayer custom control don't call the list of customers Customers, call it ItemsSource.

It might seem counter intuitive at first but it saves a lot of headache in the long run because future programmers can make a lot of assumptions about how a property called ItemsSource will act that they can't necessarily make about a Customers property.

Bryan Anderson
+1  A: 

Make sure the control can be re-styled and re-templated without changing the way the control operates. Don't make the control assume that the Listbox and Button are both within the same panel or that there even is a Listbox or Button. Check out the MSDN article on control authoring for some recommendations on how to do this.

Bryan Anderson