【发布时间】:2017-05-24 08:35:26
【问题描述】:
我在 Datagrid 中获得了我的 Image-Row 的 XAML:
<DataGridTemplateColumn x:Name="imgSettings" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image x:Name="imgSettings" Source="img/settings_blue.png" Stretch="None" MouseDown="Row_DoubleClick" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected,
RelativeSource={RelativeSource AncestorType=DataGridRow}}" Value="True">
<Setter TargetName="imgSettings" Property="Source" Value="/img/settings_white.png" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
我的Double Click 行事件是:
private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
{
Equipment classObj = clientDataGrid.SelectedItem as Equipment;
string cellValue = classObj.EQNr;
lblArtikel.Content = "Equipment: " + cellValue ;
Dispatcher.BeginInvoke((Action)(() => tbControlETK.SelectedIndex = 1));
}
这实际上有效,但现在我尝试为这个图像按钮获取相同的功能,但这给了我一个空异常,因为 MouseDown 事件在 Row 被选中之前触发......任何解决方案?
我已经想到了一个用于图像行的函数,我可以在其中获取发送者的行或类似的东西。
【问题讨论】: