20
votes

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?

1
Just as a note, if you want a nice easy implementation take a look at the MasterDetailControl in the UWP toolkit github.com/Microsoft/UWPCommunityToolkit docs.uwpcommunitytoolkit.com/en/master/controls/… - Depechie

1 Answers

37
votes

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