1

現在の問題に関する多くの解決策を読みましたが、どれも機能せず、次のことを行う方法がわかりません。

コンバーター

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() メソッドの Color は有効なオブジェクトではありません。

4

1 に答える 1

3

現在、ラベルの色プロパティをバインドしようとするのではなく、色オブジェクトを直接バインドしようとしています。

試す:

set.Bind(Label).For(l => l.Color).To(observation => observation.ObsCategorieCouleur).WithConversion(new HexToUIColorValueConverter(), null);

を含むこの流暢な構文の詳細については、https://github.com/MvvmCross/MvvmCross/wiki/Databinding#fluentForを参照してください。


これを超えて、Color自動プロパティをInvalidate、色が変更されるたびに再描画を要求するコードが内部にあるプロパティに変更することを試みる必要があります。

于 2013-10-30T17:01:49.773 に答える