How can data templates in generic.xaml get applied automatically?

Posted by Thiado de Arruda on Stack Overflow See other posts from Stack Overflow or by Thiado de Arruda
Published on 2010-05-01T22:05:21Z Indexed on 2010/05/01 22:07 UTC
Read the original article Hit count: 169

Filed under:
|
|
|
|

I have a custom control that has a ContentPresenter that will have an arbitrary object set as it content. This object does not have any constraint on its type, so I want this control to display its content based on any data templates defined by application or by data templates defined in Generic.xaml. If in a application I define some data template(without a key because I want it to be applied automatically to objects of that type) and I use the custom control bound to an object of that type, the data template gets applied automatically. But I have some data templates defined for some types in the generic.xaml where I define the custom control style, and these templates are not getting applied automatically. Here is the generic.xaml :

If I set an object of type 'PredefinedType' as the content in the contentpresenter, the data template does not get applied. However, If it works if I define the data template in the app.xaml for the application thats using the custom control.

Does someone got a clue? I really cant assume that the user of the control will define this data template, so I need some way to tie it up with the custom control.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#