Mvvmcross WithFormat()没有开火

时间:2013-10-29 14:37:19

标签: ios converter mvvmcross

我正在尝试将byte []格式化为一个字符串,以便在IOs应用程序中显示,这里是什么 问题是转换器永远不会启动 我实际上有:

转换器类

class ByteArrayToTextValueConverter : MvxValueConverter<byte[], string>
{

    protected override string Convert(byte[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value is byte[])
        {
            return "test";
            /*
            var byteArray = (byte[])value;
            return Encoding.UTF8.GetString(byteArray, 0, byteArray.Length);
             */
        }
        return "";
    }

    protected override byte[] ConvertBack(string value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value is string)
        {
            var text = (string)value;
            return Encoding.UTF8.GetBytes(text);
        }
        return new byte[] { };
    }
}

查看废料:

var source = new MvxSimpleTableViewSource(
    TableView,
    SubtitleDetailViewCell.Key,
    SubtitleDetailViewCell.Key
);
TableView.Source = source;
TableView.RowHeight = 50;

TableView.RegisterClassForCellReuse(typeof(SubtitleDetailViewCell), SubtitleDetailViewCell.Key);

var set = this.CreateBindingSet<ObservationsView, ObservationsViewModel>();
set.Bind(source).To(vm => vm.Observations);
//set.Bind(source).For(s => s.SelectionChangedCommand).To(vm => vm.SelectedObsCommand);
set.Apply();

TableView.ReloadData();

自定义单元格类:

public SubtitleDetailViewCell(IntPtr handle)
    : base(handle)
{
    Initialize();

    this.DelayBind(() =>
    {
        var set = this.CreateBindingSet<SubtitleDetailViewCell, ObservationMedicale>();
        set.Bind(MainLbl).To(observation => observation.Texte).WithConversion("ByteArrayToText");
        set.Bind(SubLeftLbl).To(observation => observation.SaisieLe);
        set.Bind(SubRightLbl).To(observation => observation.PraticienNom);
        set.Apply();

    });
}

1 个答案:

答案 0 :(得分:0)

这可能就像您的ByteArrayToTextValueConverterinternal而不是public一样简单 - 因此MvvmCross无权访问它。

如果您确实要保留internal,那么您还可以使用WithConversion的替代格式:

  .WithConversion(new ByteArrayToTextValueConverter(), null);

除此之外,我还不确定为什么要在ByteArrayToText列表中应用Observations转换 - 看起来更像是源应该是ObservationMedicale个对象的集合/ p>