Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

BindingContext of Buttons within a ListView template

$
0
0

So I'm having a little trouble with Command binding within a ListView template here.
This is my XAML code:

<ListView ItemsSource="{Binding AvailableExams}" ItemTapped="ItemTapped" HasUnevenRows="True" VerticalOptions="Fill" Grid.Row="3">
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <ViewCell.View>
              <Grid Padding="0,5,0,5">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Label Text="{Binding LVA}" FontAttributes="Bold" Grid.ColumnSpan="2" FontSize="17" HorizontalOptions="FillAndExpand" />
                <Label Text="{Binding TimeAndPlaceString}" Grid.Row="1" />
                <Button Text="Register" Command="{Binding RegisterCommand}" CommandParameter="{Binding}" Grid.RowSpan="2" Grid.Column="1" HorizontalOptions="End" VerticalOptions="Center" />
              </Grid>
            </ViewCell.View>
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>

The problem is that the BindingContext of the Button is the AvailableExam of the current row, so it can't find my Command. Is there a way to bind to the command of the outer ViewModel of my Page?

Thanks.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>