Image of Silverlight datagrid

In a silverlight application, I have a datagrid with the image as the first column (see the code below, which I use)

when I click on the image, I capture the MouseLeftButtonDown event, the problem I'm running with is that when I click on the image, the SelectedIndex in Datagrid does not change . So I don’t know the row was pressed.

<data:DataGridTemplateColumn Width="25">
    <data:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Image Width="20" Stretch="Fill" Name="Delete"  Source="/Portal;Component/Images/Delete.png" MouseLeftButtonDown="ImageDelete_MouseLeftButtonDown"/>
        </DataTemplate>
    </data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
+3
source share
2 answers

, , , , - , (, , , ), . , - "" "" .

<data:DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <Image Width="20" Stretch="Fill" Name="Delete"  Source="/Portal;Component/Images/Delete.png" MouseLeftButtonDown="ImageDelete_MouseLeftButtonDown" Tag="{Binding Id}"/>
    </DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>

, , , ... ( VB)

    Private Sub ImageDelete_MouseLeftButtonDown(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs)
        Dim img As Image = TryCast(sender, Image)
        Dim id As Integer = CInt(img.Tag)
        ' Do stuff with id
    End Sub

#:

Private void ImageDelete_MouseLeftButtonDown(System.Object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    Image img = sender as Image;
    int id = Convert.ToInt32(img.Tag);
    // do stuff with id
}

+1

e.Handled true ? , .

0

Source: https://habr.com/ru/post/1727418/


All Articles