我需要在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'的内容发生变化时进行拦截。
是否有订阅活动?
你能建议我怎么做吗?
答案 0 :(得分:1)
如果您需要检测单元格Image
上的DataContext
何时发生更改,那么执行此操作的一种方法是将属性添加到您的单元格并将该属性绑定到{{1} } - 例如
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
});
}
类型进行子类化并在该对象上提供新属性。有关此方法的示例,请参阅http://slodge.blogspot.co.uk/2013/07/n33-animating-data-bound-text-changes.html
imgPhoto
属性