2017-07-28 21 views
0

我試圖將TapGestureRecognizer添加到Label標籤TapGesture不啓動Xamarin表單

SliderAbout.GestureRecognizers.Add(new TapGestureRecognizer 
{ 
    Command = new Command(() => OpenAboutAppAsync()), 
}); 

SliderAbout是我Label至極是在XAML中設置和正常工作。

<ScrollView Grid.Row="1"> 
       <Grid VerticalOptions="Start" HorizontalOptions="Start" Margin="20,20,0,0"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="60"/> 
        </Grid.RowDefinitions> 

        <Label x:Name="SliderAbout" 
          Text="Über die APP" 
          Grid.Row="2" 
          TextColor="White" 
          FontFamily="Open Sans Light" 
          FontSize="Medium"/>  
       </Grid> 
      </ScrollView> 

的代碼也被運行(我把它放在類的構造函數)

但是當我點擊該標籤法犯規火...爲什麼它不會火?

感謝您的幫助!

+1

請出示您的佈局。該標籤是否可能位於另一個元素之下? –

+0

添加xaml代碼 – Cambaru

+0

將gesturerecognizer添加到網格,或者在網格上嘗試'InputTransparent =「true」' –

回答

0

如果您使用mvvm方法,您可以將手勢識別器直接添加到xaml以及後面代碼或視圖模型中的操作。在你的情況下,它會是這樣的:

<Label x:Name="SliderAbout" Text="Über die APP" Grid.Row="2" TextColor="White" FontFamily="Open Sans Light" FontSize="Medium"> 
    <Label.GestureRecognizers> 
     <TapGestureRecognizer Tapped="OnLabelTapped" /> 
    </LabelGestureRecognizers> 
</Label> 

而且在後面的代碼

private void OnLabelTapped (object sender, EventArgs e) 
{ 
    //Your code here 
}