我可以使Grid Tap手势发送命令,然后使元素变得不可见吗?

时间:2018-10-16 12:23:49

标签: xamarin xamarin.forms

我正在使用此模板:

t

这是XAML的后端:

k

有没有一种可以使用绑定的方法,所以当发生轻击手势时,将发送命令,但也使帧不可见。据我所知,我认为这可能是不可能的,但是我很想知道是否有人可以想到一种方法。

1 个答案:

答案 0 :(得分:1)

简单地说,您可以做的就是这样:

  • 继承INotifyPropertyChanged到您的类中。

  • 实现其方法如下:

    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void RaisePropertyChanged(string propertyName)
    {
    PropertyChangedEventHandler handler = PropertyChanged;
    if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    }
    
    private bool _isvisible=true; //so that by default it is visible
    public bool IsGridVisible { get {return _isvisible;} set {_isvisible=value; 
    RaisePropertyChanged(nameof(IsGridVisible));}}
    
  • 然后将其绑定到要隐藏的任何控件上:

  • 然后在“点击手势”命令中将其值更改为false;

    void OnTapGestureRecognizerTapped(对象发送者,EventArgs参数) {    IsGridVisible = false; }

这足以使您的代码发挥作用。

在查询的情况下还原。