Stephen S.

Hi,

I have a custom control that has a default constructor and parameterized constructor that take a boolean. The user control creates a bunch of shapes based on some complex math. The default constructor will initiate the math and create the shapes, however I am using the same control to display in the list and do not need it to display all the shapes, so I created a parameterized constructor so the user control doesn' create the "heavy" objects but rather displays some basic information. The user control is created within the datatemplate and is bound at runtime to an item in a collection, of which there could be many. How can I pass "False" to the constructor of my user control within a datatemplate for a list I need to have the user control get this parameter and not draw complex shapes.

Thanks a bunch!

-Steve



Re: Windows Presentation Foundation (WPF) Databinding to Custom Control that take parameters in a Datatemplate

Marlon Grech

Hi try this

http://www.beacosta.com/2006/03/why-should-i-use-objectdataprovider.html

hope it helps





Re: Windows Presentation Foundation (WPF) Databinding to Custom Control that take parameters in a Datatemplate

Sam Bent - MSFT

A control declared in a template is always created using the default constructor. That's the bad news, but the good news is that you can get the effect you want by adding two featues to your control:

a) a boolean property called DoNotCreateComplexShapes

b) an implementation of the ISupportInitialize interface (http://msdn2.microsoft.com/en-us/library/system.componentmodel.isupportinitialize(vs.71).aspx)

Wait until EndInit() before creating the complex shapes, and don't do it even then if DoNotCreateComplexShapes is true. Now you can declare your control in the template as

<foo:MyCustomControl DoNotCreateComplexShapes="true" ... />

and it should do what you want.






Re: Windows Presentation Foundation (WPF) Databinding to Custom Control that take parameters in a Datatemplate

Stephen S.

Thanks Sam,

appreciate the response. The sample and direction worked perfectly. I knew about all the pieces but couldn't figure out how all of it came together.

Thanks again,.

Steve