22

I have to do a Master/Detail in UWP

1- If you're in Laptop:

The responsible GridView of show the data of this person appear. So when you select a item is binded to ViewModel.

<ScrollViewer x:Name="ScrollLista" Grid.Column="0" Grid.Row="1">
            <ListView x:Name="Lista" ItemsSource="{Binding Lista}" ItemClick="Lista_ItemClick" SelectedItem="{Binding PersonaSeleccionada, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding nombre}" />
                            <TextBlock Text="{Binding apellido}" />
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </ScrollViewer>

        <Grid x:Name="CRUD" Grid.Column="1" Grid.Row="1" DataContext="{Binding PersonaSeleccionada}" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            ...

        </Grid>

2- When is a mobile:

Only will appear the list and when I select a item this should be two things.

  1. Call to ViewModel by binding using SelectedItem.
  2. Call to code behind using ItemClick, this will be in charge of calling another page.

The problem: ItemClick not working, not call to Lista_ItemClick... How can I call a method and send the item selected to code behind?

  • Just as a note, if you want a nice easy implementation take a look at the MasterDetailControl in the UWP toolkit https://github.com/Microsoft/UWPCommunityToolkit http://docs.uwpcommunitytoolkit.com/en/master/controls/MasterDetailsView/ – Depechie Jan 04 '17 at 12:08

1 Answers1

43

For click event to work, IsItemClickEnabled="True" should be added to the ListView.

Andrei Ashikhmin
  • 2,401
  • 2
  • 20
  • 34
  • 3
    Great quick answer. But this is hilarious that Visual Studio (running 2017) provides a way to double-click the ItemClick event and it does indeed add an event handler for the ItemClick but does not add the associated XAML property. What would be the point of adding the ItemClick event if it doesn't fire. Thanks MS! :) – raddevus Oct 17 '18 at 13:07