R – Does each row in a silverlight dataGrid have to have the same “RowDetailsTemplate”


I'm defining a datagrid's RowDetailsTemplate in the following way:

RowDetailsTemplate="{StaticResource defaultTemplate}"


    <DataTemplate x:Key="defaultTemplate">
            <TextBlock Text="default" x:Name="_txt" />
    <DataTemplate x:Key="otherTemplate">
            <TextBlock Text="other" x:Name="_txt" />

Is there a way to programatically define which of the two above DataTemplates a given row is to use (perhaps in the LoadingRowDetails() event)?

Best Solution

You can add the following code in your LoadingRowDetails event, obviously replacing my useless If condition with your own:

    If 1 = 1 Then
        e.Row.DetailsTemplate = CType(Resources("defaultTemplate"), DataTemplate)
        e.Row.DetailsTemplate = CType(Resources("otherTemplate"), DataTemplate)
    End If
Related Question