具有来自两个来源的数据绑定的 DataTemplate

DataTemplate with data binding from two sources

我有一个带有图像的数据模板,该图像的源 属性 绑定到默认源(可观察集合,它工作正常)。问题是我需要它的 IsVisible 属性 绑定到其他源(在我的代码后面声明的对象)但是当 运行 应用程序我在控制台上得到这个:

Binding: 'ScrollEvent' property not found on 'Xamarin.Forms.Binding', target property: 'FFImageLoading.Forms.CachedImage.IsVisible'

我的代码的相关部分:

MyPage.xaml

<DataTemplate x:Key="MapMsgSend">

 ...

   <ffimageloading:CachedImage
        Source="{Binding imageSource}" 
        IsVisible="{Binding Source={Binding MyPage}, Path=ScrollEvent.Visibility}">
   </ffimageloading:CachedImage>

 ...

</DataTemplate>

MyPage.xaml.cs(相关部分)


namespace Project.XAML
{
    public partial class MyPage : ContentPage
    {
       public MyPage(){
         this.BindingContext=this;
       }
       public IsScrolling ScrollEvent = new IsScrolling() { ShowImage = true };
    } 
}

编辑

public class IsScrolling : INotifyPropertyChanged
{
      private bool _ShowImage { get; set; }
      public bool ShowImage
      {
          get { return _ShowImage; }
          set
          {
              _ShowImage = value;
              NotifyPropertyChange("ShowImage");
          }
      }

      public event PropertyChangedEventHandler PropertyChanged;
      void NotifyPropertyChange(string PropName)
      {
          if (PropertyChanged != null)
              PropertyChanged(this, new PropertyChangedEventArgs(PropName));
      }
}

//default value
public IsScrolling ScrollEvent = new IsScrolling() { ShowImage = true };

语法应该是这样的

<ContentPage ... x:Name="page">
...

<ffimageloading:CachedImage
    Source="{Binding imageSource}" 
    IsVisible="{Binding Source={x:Reference page},Path=ScrollEvent.Visibility}"

您只能绑定到 public 属性

这是 public,但不是 属性

public IsScrolling ScrollEvent = new IsScrolling() { ShowImage = true };

需要getand/orset才能成为属性,像这样

public IsScrolling ScrollEvent { get; set; } = new IsScrolling() { ShowImage = true };