I'm trying to formatting a byte[] to a string for displaying in IOs application, here what The problem is that the Converter never fires up I actually have:
Converter class
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[] { };
}
}
View scrap:
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();
Custom cell class:
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();
});
}
This might be as simple as the fact that your ByteArrayToTextValueConverter
is internal
rather than public
- so MvvmCross doesn't have permission to access it.
If you do want to keep it internal
, then you can also use the alternative format of WithConversion
:
.WithConversion(new ByteArrayToTextValueConverter(), null);
Beyond that, I'm also unsure why you would apply the ByteArrayToText
conversion on the list of Observations
- it looks more like the source should be a collection of ObservationMedicale
objects