Alexey Titov
Alexey Titov

Reputation: 353

UWP - How to select ListViewItem when a button inside it is clicked

I have a ListView, which ListViewItems have buttons, defined in ListView.ItemTemplate. How can I select a ListViewItem upon such button's Click event? I know how to make that in WPF, but can't figure for UWP, since UWP Styles don't support triggers.

Upvotes: 0

Views: 1007

Answers (2)

Ivan I
Ivan I

Reputation: 9990

In the button clicked event add:

listView.SelectedItem = ((FrameworkElement)sender).DataContext;

Upvotes: 1

Stuart Smith
Stuart Smith

Reputation: 2051

You will have to use a delegate command

The following example shows you how to accomplish this

https://code.msdn.microsoft.com/windowsapps/How-to-bind-command-to-a-299f7759

but a simplier example is to use template 10 which has a delegate command already created for you.

https://github.com/Windows-XAML/Template10/wiki/MVVM#delegatecommand

To learn more on template 10 go to

https://mva.microsoft.com/en-us/training-courses/getting-started-with-template-10-16336

Upvotes: 0

Related Questions