【问题标题】:Detect when bind occurs in mvvmcross检测 mvvmcross 中何时发生绑定
【发布时间】:2013-07-08 09:54:12
【问题描述】:

您好我需要在 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”的内容发生变化时进行拦截。

有要订阅的事件吗?

你能建议我怎么做吗?

【问题讨论】:

    标签: mvvmcross


    【解决方案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 的任何类型进行子类化,并在该对象上提供一个新属性。有关此方法的示例,请参阅 http://slodge.blogspot.co.uk/2013/07/n33-animating-data-bound-text-changes.html 中的 AnimatingText 属性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-21
      • 2017-07-18
      • 2013-10-17
      • 2014-10-10
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多