【发布时间】:2026-01-19 02:05:01
【问题描述】:
我有一个应用程序,其中包含许多看起来都相同并执行相似任务的图像:
<Image Grid.Column="1" Grid.Row="0" Name="image_prog1_slot0" Stretch="Uniform" Source="bullet-icon.png" StretchDirection="Both" MouseDown="image_prog1_slot0_MouseDown"/>
<Image Grid.Column="1" Grid.Row="1" Name="image_prog1_slot1" Stretch="Uniform" Source="bullet-icon.png" StretchDirection="Both" />
<Image Grid.Column="1" Grid.Row="2" Name="image_prog1_slot2" Stretch="Uniform" Source="bullet-icon.png" StretchDirection="Both" />
现在,我想将每一个链接到同一个事件处理程序:
private void image_MouseDown(object sender, MouseButtonEventArgs e)
{
//this_program = ???;
//this_slot = ???;
//slots[this_program][this_slot] = some value;
}
显然,图像的程序号和槽号是其名称的一部分。有没有办法在事件处理程序被触发时提取这些信息?
【问题讨论】:
标签: c# .net wpf xaml event-handling