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

How to get BindingContext reference from a custom Cell?

$
0
0

Hi all,

Considering the XAML bellow, I have a page (StorePage) and ListView which has a DataTemplateSelector that renders different templates.
Inside I have a button that must call a command declared in the page's ViewModel.

The questions is: How can I get the page's BindingContext reference inside ?

Example:

<?xml version="1.0" encoding="UTF-8"?>

<ContentPage.Resources>
    <ResourceDictionary>
        <DataTemplate x:Key="ProductTemplate">
            <controls:ProductCell>
                <local:ProductListItemTemplate />
            </controls:ProductCell>
        </DataTemplate>
        <DataTemplate x:Key="MapTemplate">
            <ViewCell>
                <local:LocationTemplate />
            </ViewCell>
        </DataTemplate>

        <local:StoreTabTemplateSelector x:Key="TabTemplateSelector"
            Template1="{StaticResource ProductTemplate}"
            Template2="{StaticResource MapTemplate}"/>
    </ResourceDictionary>
</ContentPage.Resources>

<StackLayout Spacing="0">
    <ListView  x:Name="ListView"
        ItemsSource="{Binding Items}"
        ItemTemplate="{StaticResource TabTemplateSelector}"
        RefreshCommand="{Binding RefreshCommand}"
        IsRefreshing="{Binding IsRefreshing}"
        HasUnevenRows="True" 
        CachingStrategy="RecycleElement">
        <ListView.Behaviors>
            <b:EventToCommandBehavior EventName="ItemAppearing" 
                                              Command="{Binding LoadMoreCommand}" 
                                              EventArgsParameterPath="Item" />
        </ListView.Behaviors>
    </ListView>
</StackLayout>


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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