我有一个绑定到业务类的 DataTemplate,它还包含一个 StackPanel:
<DataTemplate DataType="{x:Type logic:Sensor}">
<StackPanel Name="SensorPanel" MouseDown="SensorPanel_MouseDown">
<TextBlock Name="ID" Text="{Binding}" ></TextBlock>
<TextBlock Name="Type" Text="{Binding Type}"></TextBlock>
</StackPanel>
</DataTemplate>
当我单击堆栈面板时,我想通过 sender 参数获取“逻辑:传感器”的实例。
private void SensorPanel_MouseDown(object sender, MouseButtonEventArgs e)
{
}
有没有办法以这种方式到达它?