【发布时间】:2017-11-22 10:59:43
【问题描述】:
当我单击重定向到新窗口的图标时,它会打开相同的视图两次。而且我不知道如何处理它只打开一个视图。
示例 xaml 按钮
<local:AnimatedImage Grid.Column="2" Source="googlemap_view_search.png"
HorizontalOptions="Center" VerticalOptions="Center" Margin="16,0">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding SearchCommand}" />
</Image.GestureRecognizers>
</local:AnimatedImage>
自定义动画图像类
public class AnimatedImage : Image
{
private const int ANIMATED_TIME = 100;
private const double INITIAL_VALUE = 1;
private const double MAGNIFICATION_VALUE = 1.3;
public static readonly BindableProperty CommandProperty = BindableProperty.Create<AnimatedImage, ICommand>(p => p.Command, null);
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create<AnimatedImage, object>(p => p.CommandParameter, null);
public object CommandParameter
{
get { return (object)GetValue(CommandParameterProperty); }
set { SetValue(CommandParameterProperty, value); }
}
private ICommand TransitionCommand
{
get
{
return new Command(async () =>
{
this.AnchorX = 0.48;
this.AnchorY = 0.48;
await this.ScaleTo(MAGNIFICATION_VALUE, 50, Easing.Linear);
await Task.Delay(ANIMATED_TIME);
await this.ScaleTo(INITIAL_VALUE, 50, Easing.Linear);
if (Command != null)
{
Command.Execute(CommandParameter);
}
});
}
}
public AnimatedImage()
{
Initialize();
}
public void Initialize()
{
GestureRecognizers.Add(new TapGestureRecognizer()
{
Command = TransitionCommand
});
}
}
}
在 ViewModel 中 public DelegateCommand SearchCommand { get;私人套装; } 和
await NavigateToPage(new SearchPage());
【问题讨论】:
-
每次调用getter都返回
new Command?
标签: c# xamarin.forms