DataGridTemplateColumn DataTemplate Changing

Aug 13, 2009 at 5:43 PM

Hello,

In my project I have a DataGrid with 3 DataGridTemplateColumn, one containing a DatePicker, another containing a ComboBox and the final one a TextBox in CellEditingTemplate and each one containg TextBlock in CellTemplate.
Example:
<toolkit:DataGridTemplateColumn x:Name="" Header="" Width="48">
    <toolkit:DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <ComboBox SelectedItem="" ItemsSource="">
            </ComboBox>
        </DataTemplate>
    </toolkit:DataGridTemplateColumn.CellEditingTemplate>
    <toolkit:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Border BorderBrush="Black" BorderThickness="1" CornerRadius="0" MinWidth="48">
                <TextBlock Text="" />
            </Border>
        </DataTemplate>
    </toolkit:DataGridTemplateColumn.CellTemplate>
</toolkit:DataGridTemplateColumn>

I need that the selected row have a different DataTemplate, in the CellTemplate,similar to the CellEditingTemplate, to the user see that in this row we have some editable fields, but I want that the other rows shows only  the text, and I have not succeeded doing this, because I'm new at WPF.

Any idea about how to do this?

Many thanks,
Paulo

 

Aug 14, 2009 at 6:17 AM

I haven't tried it, but copying the CellEditingTemplate into a trigger (on IsSelected == true) in the CellTemplate might be worth a try.

Aug 14, 2009 at 8:59 AM

Hello,

Thanks for your reply.

Can you please post an example how to use a trigger IsSelected on the CellTemplate of a DataGridTemplateColumn.

Many thanks,
Paulo

Aug 14, 2009 at 9:49 AM

Actually, a quick Google search (I'm feeling helpful today ;)) turned up what seems like a better approach. The third hit from wpf datagrid celltemplate trigger is on Vincent Sibal's blog and looks very promising, and there are also several other interesting-looking hits on the first page alone. You may want to have a look at that and see if any of it is applicable to your particular scenario.

Aug 14, 2009 at 12:05 PM

Hello,

I found another solution, I used a DataTrigger <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type toolkit:DataGridCell}, AncestorLevel=1}, Path=IsSelected}" Value="True">and with it I can get if the Row is selected.

Thanks for your replies.
Paulo