我有以下页面:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Taps"
x:Class="Taps.MainPage">
<ContentPage.Resources>
<ResourceDictionary>
<local:AboutViewModel x:Key="AboutViewModel" />
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout BindingContext="{StaticResource AboutViewModel}">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ShowHiddenTextCommand}" NumberOfTapsRequired="5" />
</StackLayout.GestureRecognizers>
<StackLayout Orientation="Horizontal" VerticalOptions="Center" HorizontalOptions="Center">
<Image HeightRequest="77" WidthRequest="115" />
<Label Text="MyApp" FontSize="48" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" />
</StackLayout>
<Label Text="My name" />
<Label Text="1.0.00" />
<Label Text="Platform" />
<Label TextColor="Blue" Text="Open Stackoverflow">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding OpenStackOverflowCommand}" />
</Label.GestureRecognizers>
</Label>
<Editor IsEnabled="False" Text="{Binding HiddenText}" IsVisible="{Binding ShowHiddenText}" />
</StackLayout>
</ContentPage>
查看模型:
using System;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Xamarin.Forms;
namespace Taps {
public sealed class AboutViewModel : ViewModelBase {
public string HiddenText { get; } = "Some text";
private bool showHiddenText;
public bool ShowHiddenText {
get => showHiddenText;
private set => Set(() => ShowHiddenText, ref showHiddenText, value);
}
private RelayCommand showhiddenTextCommand;
public RelayCommand ShowHiddenTextCommand => showhiddenTextCommand ?? (showhiddenTextCommand = new RelayCommand(() => ShowHiddenText = true));
private RelayCommand openStackOverflowCommand;
public RelayCommand OpenStackOverflowCommand => openStackOverflowCommand ?? (openStackOverflowCommand = new RelayCommand(() => Device.OpenUri(new Uri("http://stackoverflow.com"))));
}
}
当点击堆栈面板所需的次数时,这似乎没有显示隐藏的编辑器。它似乎适用于运行Android 5.1的Moto G,但不适用于iPod Touch而不适用于UWP。
标签点击似乎在所有平台上都能正常工作,所以我不确定发生了什么。如何在指定的点击次数后触发ShowHiddenTextCommand
?
我正在使用最新的Xamarin.Forms和MvvmLight库。