1

I need get the id of an images which is place inside a datatemplate.. the code is given below.

<sdk:DataGrid.Columns>
 <sdk:DataGridTemplateColumn x:Name="colDeleteContent" IsReadOnly="True" Header="Delete Content" Width="100" CanUserResize="False">
   <sdk:DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
         <StackPanel x:Name="spDeleteContent" VerticalAlignment="Center" Margin="10,0,0,0" Width="20" Height="20" HorizontalAlignment="Center" Orientation="Vertical">
             <Image x:Name="imgDeleteContent" Source="Assets/Images/close.png" Height="15" Tag="Assets/Images/close.png" Width="15" Margin="0" Cursor="Hand" Opacity="0" />
         </StackPanel>
       </DataTemplate>
     </sdk:DataGridTemplateColumn.CellTemplate>
   </sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>

I need to get the id of the "imgDeleteContent" which i have placed inside that datatemplate stackpanel in my code behind.

Pls help, Thanks

Arun
  • 1,644
  • 9
  • 25
  • 41
  • Do you know the index of the row, the image of which you want to find? – vortexwolf May 04 '12 at 18:43
  • @vorrtex i don't know the index of the row, i didn't get your point.. that image is placed in zeroth (0th) column in the data grid. thanks for your reply. – Arun May 06 '12 at 23:15
  • First, you should retrieve the row by index, here is the example: http://stackoverflow.com/a/4065667/427225. Then you should retrieve the cell value, like here: http://stackoverflow.com/a/3121715/427225. After that you can try to cast the element to StackPanel and find the image. But it would be much easier and better to use view models and data binding. – vortexwolf May 07 '12 at 09:57

1 Answers1

1

You could find control name on grid loading row event like below

StackPanel Sp = grdProducts.Columns[1].GetCellContent(e.Row) as StackPanel;

then use quick watch to find that imgDeleteContent control. and do whatever yo like :)

Sankar M
  • 4,549
  • 12
  • 37
  • 55