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

How to bind to Command of button in listview when itemssource is set?

$
0
0

How do I change the binding context of a button inside a listview, (its a call button for a contact essentially), when the itemssource is set to an observable collection but the Command is in the view model that is the bindingcontext for the view? The class for TestButtonCommand is PatSrchVM and itemssource for the list is bound to an observable collection called PatientList in PatSrchVM. The binding context was set using the ViewFactory.

<toolkit:BaseView.Content>
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
      <SearchBar Grid.Row="0" Text="{Binding SearchText}" SearchCommand="{Binding SearchCMD}" Placeholder="Search Patients"/>
        <ListView ItemsSource="{Binding PatientList}" Grid.Row="1"  x:Name="PatientListCtrl">
          <ListView.ItemTemplate>
            <DataTemplate>
              <controls:ExtendedViewCell SeparatorPadding="0,0,0,0" SeparatorColor="Red" ShowDisclousure="True">
                <controls:ExtendedViewCell.View>
                  <StackLayout Orientation="Horizontal">
                    <StackLayout Padding="15,0,0,0">
                      <Label Text="{Binding Pat_name}" Font="30"></Label>
                      <Button Text="Test" Command="{Binding TestButtonCommand}/>
                    </StackLayout>
                  </StackLayout>
                </controls:ExtendedViewCell.View>
              </controls:ExtendedViewCell>
            </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>
      </Grid>
  </toolkit:BaseView.Content>

</toolkit:BaseView>

Viewing all articles
Browse latest Browse all 58056

Trending Articles