我正在尝试将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();
});
}
答案 0 :(得分:0)
这可能就像您的ByteArrayToTextValueConverter
是internal
而不是public
一样简单 - 因此MvvmCross无权访问它。
如果您确实要保留internal
,那么您还可以使用WithConversion
的替代格式:
.WithConversion(new ByteArrayToTextValueConverter(), null);
除此之外,我还不确定为什么要在ByteArrayToText
列表中应用Observations
转换 - 看起来更像是源应该是ObservationMedicale
个对象的集合/ p>