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

x:Reference not working?

$
0
0

I'm trying to use a view-to-view binding using x:Reference, but am having no luck. Specifically, I am binding the command/parameter of a TextCell's context actions menu. I wish to bind the command itself to an ICommand property of the main view model, while keeping the command parameter bound to the current item of the ListView that contains the cells. So this means using x:Reference as the Source of the command binding. Yet this doesn't seem to work.

I tried digging through the Xamarin Forms code using dotPeek to see if I could figure out what was going wrong - and I don't even see a ReferenceExtension class in XF 1.3 (Stable)?? Was this removed from the platform, or am I just looking in the wrong place?

My code looks very similar to this, however the binding's Source is totally being ignored:

<ListView ItemsSource="{Binding EventsList}"
          x:Name="EventsList">
  <ListView.ItemTemplate>
    <DataTemplate>
      <TextCell Text="{Binding Name}">
        <TextCell.ContextActions>
          <MenuItem Text="Delete" 
                    IsDestructive="True"
                    Command="{Binding Path=BindingContext.DeleteEventCommand, Source={x:Reference Name=EventsList}}"
                    CommandParameter="{Binding}"/>
        </TextCell.ContextActions>
      </TextCell>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

The ListView's BindingContext is a viewmodel class that has an ObservableCollection of items named EventsList, as well as an ICommand named DeleteEventCommand.


Viewing all articles
Browse latest Browse all 75885

Trending Articles



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