I have the following code which populates my user control in form of rows and column. The user control which is being populated contains Button, links, textbox etc. When a certain button is pressed on a particular User Control in a particular row/column, I need to know for which User Control that button was pressed. Here is the XAML that is populating the user controls in rows and columns
<ItemsControl ItemsSource="{Binding Templates}" Width="{Binding GridWidth}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding NumColumns}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Column" Value="{Binding ColumnIndex}" />
<Setter Property="Grid.Row" Value="{Binding RowIndex}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
</ItemsControl>
Templates is basically a collection of UserControls that are being populated in Rows/Columns. Preferably I want to do this in ViewModel but solution in code behind for now will work as well.
ItemsControl
can't select items, only present collections. Only a Selector or one of it's descendants can select items.
For your scenario, I think a ListView with GridView would fit. When the user would click a control in the line, the event would bubble to the ListView
and the item would get selected. You can override the default styles so it wouldn't display as selected line: WPF ListView turn off selection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With