Hi all! After some research and after following some guides I have not yet managed to use a listview with a custom cell,
my problem is that when I fill the list with the model class the views are not initialized with the data.
my view class is
public class TrafficView : ViewCell
{
public static readonly BindableProperty ByteProperty = BindableProperty.Create("mbyte", typeof(string), typeof(TrafficView),"");
public static readonly BindableProperty ProgressProperty = BindableProperty.Create("progress", typeof(double), typeof(TrafficView), 0.0);
public static readonly BindableProperty CountryProperty = BindableProperty.Create("country", typeof(string), typeof(TrafficView), "");
private static void mbytePropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
//((TrafficView)bindable).Byte = newValue.ToString();
}
public string mbyte
{
get
{
return (string)GetValue(ByteProperty);
}
set
{
SetValue(ByteProperty, value);
this.pBar.LabelStringFormat = value;
}
}
public double progress
{
get
{
return (double)GetValue(ProgressProperty);
}
set
{
SetValue(ProgressProperty, value);
this.pBar.Progress = value;
}
}
public string country
{
get
{
return (string)GetValue(CountryProperty);
}
set
{
SetValue(CountryProperty, value);
this.country.Text = value;
}
}
public TrafficView()
{
initView();
}
public ProgressBarView pBar { get; set; }
public String total { get; set; }
public Label country { get; set; }
private void initView()
{
.............................. some code ............................
SetBinding(ByteProperty, new Binding("mbyte"));
SetBinding(ProgressProperty, new Binding("progress"));
SetBinding(CountryProperty, new Binding("country"));
this.BindingContext = this;
}
}
my model is
public class TrafficModel
{
public string country { get; set;}
public double progress { get; set;}
public string mbyte { get; set;}
public TrafficModel(String mbyte,double progress,String country)
{
this.country = country;
this.progress = progress;
this.mbyte = mbyte;
}
public TrafficModel(){
country = "";
progress = 0;
mbyte = "0";
}
}
and my list view
ListView soglieListView = new ListView();
soglieListView.RowHeight = 140;
soglieListView.SeparatorColor = Color.White;
soglieListView.ItemTemplate = new DataTemplate(typeof(TrafficView));
ObservableCollection<TrafficModel> trafficList = new ObservableCollection<TrafficModel>();
for (int i = 0; i < soglie.Count;i++){
trafficList.Add(new TrafficModel("Prova",3,"Prova"));
}
soglieListView.ItemsSource = trafficList;
what I did not understand?