Relative context for tap gestures

I want to bind to command from context outside of my data template. I may do it using Button control and EventToCommand behavior. However I haven't found a way to do it for tap gestures.

Here is a small example when I want to present a small tree structure of tags (tag only has name and children properties). My intention is to go to edit page after clicking tag name without a need to have special button

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"             
                 xmlns:controls="clr-namespace:MyProject.Controls;assembly=TaskChaos"
                 xmlns:mvvm="clr-namespace:MyProject.Mvvm;assembly=TaskChaos"
                 prism:ViewModelLocator.AutowireViewModel="True"
                 x:Class="MyProject.Views.TagManagementPage"
                 x:Name="TagPage">
      <ContentPage.Resources>
        <ResourceDictionary>
          <DataTemplate x:Key="Tag">
            <StackLayout Orientation="Vertical">          
              <StackLayout Orientation="Horizontal">
                <Label Text="{Binding Name}" Margin="2">
                  <!--<Label.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding GotoEditTagCommand}" CommandParameter="{Binding }"></TapGestureRecognizer>
                  </Label.GestureRecognizers>-->
                </Label>
                <Button Text="Edit">
                  <Button.Behaviors>
                    <mvvm:EventToCommandBehavior CommandNameContext="{mvvm:RelativeContext TagPage}" CommandName="GotoEditTagCommand" CommandParameter="{Binding }" EventName="Clicked" />
                  </Button.Behaviors>
                </Button>
              </StackLayout>
              <controls:RepeaterView ItemsSource="{Binding Children}" ItemTemplate="{StaticResource Tag}" Margin="15, 2, 2, 2" />
            </StackLayout>
          </DataTemplate>
        </ResourceDictionary>
      </ContentPage.Resources>
      <controls:RepeaterView ItemsSource="{Binding Tags}" Spacing="2" ItemTemplate="{StaticResource Tag}">    
      </controls:RepeaterView>

    </ContentPage>

Any ideas how to make it work also for tap gestures?

Answers

  • ZoliZoli NLMember ✭✭

    No solution yet?
    I have a listview with image, and want to bind the TapGestureRecognizer command of the image to a command outside of the listview.item context (to the main viewmodel, which contains the listview)

Sign In or Register to comment.