Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify a default empty DataTemplate instead of the default 'ToString()' DataTemplate

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?

like image 856
J W Avatar asked Apr 02 '09 14:04

J W


1 Answers

If you are using the MVVM pattern and have an abstract class which all your ViewModel classes derive from, you can use that class instead of System.Object:

<Grid.Resources>
    <DataTemplate DataType="{x:Type vm:VMBase}">
    </DataTemplate>
</Grid.Resources>
like image 106
Greg Sansom Avatar answered Oct 10 '22 05:10

Greg Sansom