First i love the product and i will continue to develop apps with xamarin professionally and personally.
I am trying to bind a list into another list and the new list has to be horizontal. Here is mock up of the items I want.
And heres how it currently looks on the market.
My first attempt was using xaml and I could not get the second list to show up correctly. For example, the second items would not display horizontal.
Which bring me to my current problem with OnBindingContextChanged.
public partial class MainPage : ContentPage
{
public List<LotteryBall> ballz { get; set; }
public MainPage ()
{
pageload ();
}
public async void pageload()
{
ListView lst = new ListView ();
LotteryBallController lbc = new LotteryBallController ();
this.ballz = await lbc.GetLotteryFeedbyProviderid ();
lst.ItemsSource = ballz;
lst.ItemTemplate = new DataTemplate (typeof(DynamicTemplateLayout));
this.Content = lst;
}
}
public class DynamicTemplateLayout : ViewCell
{
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
dynamic c = BindingContext;
View = BuildRow (c);
}
public View BuildRow(object lotball)
{
LotteryBall lb = (LotteryBall)lotball;
var thelayout = new StackLayout {VerticalOptions = LayoutOptions.StartAndExpand};
var typeholder = new StackLayout ();
typeholder.BackgroundColor = Color.Navy;
Label lbltypeheader = new Label {
Text = lb.title,
Font = Font.SystemFontOfSize (25, FontAttributes.Bold),
HorizontalOptions = LayoutOptions.Center,HeightRequest = 1000
};
typeholder.Children.Add (lbltypeheader);
foreach (var ball in lb.balls) {
var balll = new StackLayout ();
Label lblball = new Label {
Text = ball.number,
Font = Font.SystemFontOfSize (25, FontAttributes.Bold),
HorizontalOptions = LayoutOptions.Center,
TextColor = Color.Blue
};
balll.Children.Add (lblball);
var backgroundImage = new Image { };
backgroundImage.Source = ImageSource.FromFile("yellowball.png");
AbsoluteLayout ballimagelayout = new AbsoluteLayout {
Children = {
{ backgroundImage, new Rectangle (0, 0, 1, 1), AbsoluteLayoutFlags.All },
{ balll, new Rectangle (0, 0, 1, 1), AbsoluteLayoutFlags.All }
}
};
thelayout.Children.Add (typeholder);
thelayout.Children.Add (ballimagelayout);
}
return thelayout;
}
}
This method works great for building the views how I want them but anytime start adding to thelayout the item doesn't expand it just cuts it off. The only bandaid I found was setting the row height to a static value. This is not ideal. Is there a better way? Is this a bug? If you would like to project I'll send it to you. Thank you.