C# How to Identify Caller for Template Events

Posted by mikeknoop on Stack Overflow See other posts from Stack Overflow or by mikeknoop
Published on 2010-06-13T07:07:23Z Indexed on 2010/06/13 7:12 UTC
Read the original article Hit count: 117

Filed under:
|
|

I have a ListBox container data bound and templatized as so:

    <ListBox x:Name="ListBox" 
             ItemsSource="{Binding Source={StaticResource List}}"
             ItemTemplate="{StaticResource ListTemplate}">
    </ListBox>

Within my ListTemplate resource, I define a Grid which contains a few child elements. I have setup a click event handler on one of child elements. The event hander is not row-specific, and I need a (best practice) way of identifying which row in the ListBox the event fired upon.

From my data source, I have an unique ID which corresponds to the row. I do not currently expose this ID in the data binding, though could. Ideally I would like the event handler to be able to identify the ID of the row the event was fired upon.

Thank you!

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf