2

I have a DataTemplate that is bound to a buisness class, it also contains a 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>

When I click on the Stack panel I want to get the instance of the 'logic:sensor' via the sender parameter.

    private void SensorPanel_MouseDown(object sender, MouseButtonEventArgs e)
    {

    }

Is there any way to get to it this way?

svick
  • 236,525
  • 50
  • 385
  • 514
liranxs
  • 67
  • 1
  • 1
  • 4

1 Answers1

1

Cast the sender to FrameworkElement and retrieve the DataContext property.

svick
  • 236,525
  • 50
  • 385
  • 514
flq
  • 22,247
  • 8
  • 55
  • 77