我已经阅读了很多关于当前问题的解决方案,但没有一种解决方案有效,我不知道如何解决以下问题:
转换器
public class HexToUIColorValueConverter : MvxValueConverter<int, UIColor>
{
protected override UIColor Convert(int value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return UIColor.FromRGB(
(((float)((value & 0xFF0000) >> 16)) / 255.0f),
(((float)((value & 0xFF00) >> 8)) / 255.0f),
(((float)(value & 0xFF)) / 255.0f)
);
}
}绑定
public SubtitleDetailViewCell(IntPtr handle)
: base(handle)
{
Initialize();
this.DelayBind(() =>
{
Accessory = UITableViewCellAccessory.DisclosureIndicator;
var set = this.CreateBindingSet<SubtitleDetailViewCell, ObservationMedicale>();
set.Bind(MainLbl).To(observation => observation.Texte).WithConversion(new ByteArrayToStringValueConverter(), null);
set.Bind(LeftDetailLbl).To(observation => observation.SaisieLe).WithConversion(new StringFormatValueConverter(), "d MMM, HH:mm");
set.Bind(RightDetailImgLbl.Label).SourceDescribed("PraticienNom + ' ' + PraticienPrenom");
set.Bind(Label.Color).To(observation => observation.ObsCategorieCouleur).WithConversion(new HexToUIColorValueConverter(), null);
set.Apply();
});
}绑定对象
using System;
using System.Drawing;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace Next.Client.Application.iOS.Views.UI
{
[Register("CellLabelView")]
public class CellLabelView : UIView
{
public UIColor Color { get; set; }
public CellLabelView()
{
Initialize();
}
public CellLabelView(IntPtr handle)
: base(handle)
{
}
public CellLabelView(RectangleF bounds)
: base(bounds)
{
Initialize();
}
void Initialize()
{
BackgroundColor = UIColor.Clear;
Opaque = false;
}
public override void Draw(RectangleF rect)
{
base.Draw(rect);
// get graphics context
using (CGContext gc = UIGraphics.GetCurrentContext())
{
// set up drawing attributes
gc.SetLineWidth(1);
_color.SetFill();
UIColor.Clear.SetStroke();
//create geometry
var path = new CGPath();
path.AddLines(new PointF[]{
new PointF (0, 0),
new PointF (0, 8),
new PointF (4, 4),
new PointF (8, 8),
new PointF (8, 0)
});
path.CloseSubpath();
//add geometry to graphics context and draw it
gc.AddPath(path);
gc.DrawPath(CGPathDrawingMode.FillStroke);
}
}
}
}我不明白它是如何绑定颜色的,CellLabel上的SET方法从未被调用过,所以我在Draw()方法中的颜色不是一个有效的对象。
发布于 2013-10-30 17:01:49
目前,您正在尝试直接绑定颜色对象,而不是试图绑定标签上的颜色属性。
尝试:
set.Bind(Label).For(l => l.Color).To(observation => observation.ObsCategorieCouleur).WithConversion(new HexToUIColorValueConverter(), null);有关此流利语法(包括For )的详细信息,请参阅https://github.com/MvvmCross/MvvmCross/wiki/Databinding#fluent。
除此之外,您可能还应该尝试将您的Color auto属性更改为具有某些代码的属性,每当颜色发生更改时,该属性通过Invalidate请求重绘。
https://stackoverflow.com/questions/19689004
复制相似问题