2

我有一个绑定到业务类的 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)
    {

    }

有没有办法以这种方式到达它?

4

1 回答 1

1

将发件人投射到该属性FrameworkElement并检索该DataContext属性。

于 2012-03-15T21:52:30.097 回答