Reputation: 67
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?
Upvotes: 2
Views: 117
Reputation: 22859
Cast the sender to FrameworkElement
and retrieve the DataContext
property.
Upvotes: 1