The default DataTemplate in a wpf application displays the result of the .ToString() method. I’m developing an application where the default DataTemplate should display nothing.
I’ve tried:
<Grid.Resources> <DataTemplate DataType='{x:Type System:Object}'> <Grid></Grid> </DataTemplate> </Grid.Resources>
But this doesn’t work. Does anyone knows if this is possible without specifiing a specific DataTemplate for every class type in the application?
I know of no way to do this. As per Joe’s comment below, WPF specifically disallows specifying a
DataTemplatefor typeObject.Depending on your exact requirements, it may be easier to search for a
DataTemplatethat matches the specific type. If you find one, use it. Otherwise, display nothing. For example:And in your selector (pseudo-code, obviously):