2

嗨,我需要在 mvvmcross 项目中发生绑定时进行拦截。

我有我绑定的 MvxCollectionViewCell:

public ProjectsCollectionCell (IntPtr handle) 
    : base (string.Empty, handle)
{
    this.DelayBind(() => {

        var set = this.CreateBindingSet<ProjectsCollectionCell, ViewItem>();
        set.Bind (lblTitle).To (prj => prj.MnemonicId);
        set.Bind (lblDescription).To (prj => prj.Description);
        set.Bind(imgPhoto).For (s => s.Image).WithConversion("ImageArray").To(prj => prj.Image);
        set.Apply();

        if (imgPhoto.Image != null) {
            this.imgPhoto.Layer.RasterizationScale = UIScreen.MainScreen.Scale;
            this.imgPhoto.Layer.ShouldRasterize = true;
            this.imgPhoto.Layer.BorderWidth = 10;
            this.imgPhoto.Layer.BorderColor = UIColor.White.CGColor;
            this.imgPhoto.Layer.CornerRadius = 8f;
            this.imgPhoto.Layer.MasksToBounds = true;
            this.imgPhoto.Layer.Position = new PointF(imgPhoto.Frame.Left - 80, imgPhoto.Frame.Bottom);
            this.imgPhoto.Transform = CGAffineTransform.MakeRotation(-0.05f);
        };
    });
}

我想在“imgPhoto”的内容发生变化时进行拦截。

有要订阅的活动吗?

你能建议我怎么做吗?

4

1 回答 1

1

如果您需要检测Image您的单元格何时DataContext更改,那么执行此操作的一种方法是将属性添加到您的单元格并将该属性绑定到您的DataContext- 例如

  private byte[] _bytes;
  public byte[] Bytes
  {
      get { return _bytes; }
      set
      {
          _bytes = value;
          // your code here...
      }
  }

  public ProjectsCollectionCell (IntPtr handle) 
       : base (string.Empty, handle)
  {

       this.DelayBind(() => {

             var set = this.CreateBindingSet<ProjectsCollectionCell, ViewItem>();
             set.Bind(_hook).For(h => h.CurrentSource);
             set.Bind (lblTitle).To (prj => prj.MnemonicId);
             set.Bind (lblDescription).To (prj => prj.Description);
             set.Bind(this).For(s => s.Bytes).WithConversion("ImageArray").To(prj => prj.Image);
             set.Apply();

             // etc
         });
  }

作为替代方案,您可能还需要考虑对任何类型进行子类化imgPhoto并在该对象上提供新属性。有关此方法的示例,请参阅http://slodge.blogspot.co.uk/2013/07/n33-animating-data-bound-text-changes.htmlAnimatingText中的属性

于 2013-07-10T13:10:27.977 回答