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

How to reference BindingContext of ContentPage inside ContentPage.Resources?

$
0
0

Hey.

I have a ContentPage which contains ContentPage.Resources which contains a DataTemplate for my ListView and inside that DataTemplate I try to reference the BindingContext of my ContentPage to bind a button to a Command, but this is the exception I get thrown:

Can not find the object referenced by 'PageName'

This is a barebones version of what my Page looks like:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage x:Name="PageName" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="App.Page">
    <ContentPage.Resources>
        <ResourceDictionary>

            <DataTemplate x:Key="ItemTemplate">
                <ViewCell>

                    <Button Command="{Binding Path=BindingContext.DoSomethingCommand, Source={x:Reference PageName}}"/>

                </ViewCell>
            </DataTemplate>

        </ResourceDictionary>
    </ContentPage.Resources>

    <syncfusion:SfListView ItemsSource="{Binding List}" ItemTemplate="{StaticResource ItemTemplate}"/>

</ContentPage>

Why can't I reference PageName inside the DataTemplate? How do I get around this issue to be able to reference the BindingContext of my page inside the DataTemplate?

I would really appreciate some help. Thanks guys!


Viewing all articles
Browse latest Browse all 89864

Trending Articles



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