Get selectedItem in ItemsPanelTemplate

134 views Asked by At

I have the following code which posts buttons in rows and columns.

<ItemsControl ItemsSource="{Binding MyCollection}">
<!-- ItemsPanelTemplate -->
<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <UniformGrid Columns="2" />
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<!-- ItemTemplate -->
<ItemsControl.ItemTemplate>
    <DataTemplate>
        <Button Content="{Binding }" />
    </DataTemplate>
</ItemsControl.ItemTemplate>

Here is my collection which populates the user controls

private Collection<TemplateView> _myCollection; 
public Collection<TemplateView> MyCollection
{ 
    get { return _myCollection; } 
    set { _myCollection = value; } 
}

How do I know which particular button is pressed? (row/column would suffice). Many thanks in advance :)

0

There are 0 answers