2013-07-10 56 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