2013-07-10 35 views
2

您好我需要在mvvmcross项目中绑定occour时拦截。在mvvmcross中绑定occours时检测

我有我的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”改变的内容。

是否有订阅活动?

你能建议我该怎么做?

回答

1

如果您需要检测单元格DataContext上的Image何时发生更改,则执行此操作的一种方法是将该属性添加到您的单元格并将该属性绑定到您的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是和对象上提供了一个新的属性。有关此方法的示例,请参阅AnimatingText属性http://slodge.blogspot.co.uk/2013/07/n33-animating-data-bound-text-changes.html

+0

谢谢!斯图尔特总统! – Babba