0

I want to bind Id field to tag of Image which inside column of Xceed DataGrid.

<xcdg:Column FieldName="D" Title="Delete" Width="50" CellHorizontalContentAlignment="Center" CellVerticalContentAlignment="Center">
    <xcdg:Column.CellContentTemplate>
        <DataTemplate>
            <Image Source="{StaticResource imgDelete}" Tag="{Binding Id}" Width="16" Height="16" Cursor="Hand" 
                   x:Name="imgEdit" MouseLeftButtonUp="imgDelete_MouseLeftButtonUp" ToolTipService.ToolTip="Edit" />
        </DataTemplate>
    </xcdg:Column.CellContentTemplate>
</xcdg:Column>

But in event handler I am getting Tag as null:

private void imgDelete_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    AreaId = Convert.ToInt32((sender as Image).Tag);
    catch (Exception en)
}
Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
kunal2u
  • 11
  • 3
  • see http://stackoverflow.com/a/15445099/1271037 and http://stackoverflow.com/a/20204275/1271037 – dovid Jan 05 '14 at 14:58
  • From where this `Id` is coming? – Rohit Vats Jan 05 '14 at 15:32
  • Also check output window if there are any binding errors logged in it. – Rohit Vats Jan 05 '14 at 15:38
  • @RohitVats It is property inside the Observable Collection bound to datagrid. – kunal2u Jan 05 '14 at 17:57
  • See output window. Do you see any binding error reported there? – Rohit Vats Jan 05 '14 at 18:16
  • @RohitVats Yes. 'D' property not found on 'object' ''Area' (HashCode=3791685)'. BindingExpression:Path=E; DataItem='Area' (HashCode=3791685); target element is 'DataCell' (Name=''); target property is 'Content' (type 'Object'). How can I have two or more fields referring to same property 'id' in exceed datagrid? I gave fieldname as 'D' because it is not allowing me to use 'Id' as fieldname as I have it for another column. And I also want to bind Id to Tag of Image inside my column as shown above. – kunal2u Jan 05 '14 at 18:20

1 Answers1

0

I solved this as, I put it inside Column definition and then used,

kunal2u
  • 11
  • 3