DataTemplate with DataType

Mar 6, 2009 at 9:24 AM
I am missing some points. I have a single text column in DataGrid which depending on the type (double or custom type) should pick different DataTemplate. I tried implicit selector in the DataGrid resources with DataGridTextColumn bound to the property to be displayed. DataTemplates were not applied and instead a default ToString() was used (I as could see in the output). I wanted then to use DataGridTemplateColumn but then I do not understand who I can use implicit selection. I am very reluctant to write a code selector as I am sure there should be xaml-only way to accompish it.

                    <DataTemplate DataType="{x:Type s:Double}">
                        <TextBlock Text="{Binding Path=Value, Mode=OneTime, StringFormat=N2}"/>


                    <DataTemplate DataType="{x:Type engine:CustomType}">
                            <TextBlock Text="{Binding Path=value1, Mode=OneTime}"/>
                            <TextBlock Text="{Binding Path=value2, Mode=OneTime}"/>