Data binding mvvm无法为绑定创建目标绑定
我已经读了很多关于当前问题的解决方案,但是没有一个有效,我也不能 了解如何执行以下操作: 转换器Data binding mvvm无法为绑定创建目标绑定,data-binding,mvvmcross,uicolor,Data Binding,Mvvmcross,Uicolor,我已经读了很多关于当前问题的解决方案,但是没有一个有效,我也不能 了解如何执行以下操作: 转换器 public class HexToUIColorValueConverter : MvxValueConverter<int, UIColor> { protected override UIColor Convert(int value, Type targetType, object parameter, System.Globalization.CultureInfo c
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)
);
}
}
我不明白它如何无法绑定颜色,CellLabel上的SET方法从未被调用,因此Draw()方法中的我的颜色不是有效的对象。目前,您正在尝试直接绑定颜色对象,而不是尝试绑定标签上的颜色属性 尝试: 有关此流畅语法的详细信息,包括的,请参阅
除此之外,您可能还应该尝试将您的
Color
auto属性更改为一个属性,该属性中包含一些代码,每当颜色发生更改时,都会通过Invalidate
请求重新绘制。效果非常好!非常感谢你的回答,我对c#和mvvmcross都是新手,你的干预对我帮助很大
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);
}
}
}
}
set.Bind(Label).For(l => l.Color).To(observation => observation.ObsCategorieCouleur).WithConversion(new HexToUIColorValueConverter(), null);