I have a List View with header and multiple rows. I can able to fix the Headers based on Screen Size. But I unable to fix the Data based on Screen Size.
Here is my code.
Row LayOut:
public class CICell : ViewCell
{
public CICell()
{
var numberLabel = new Label{
WidthRequest = 30, // I need these should be dynamic
};
numberLabel.SetBinding (Label.TextProperty, "No");
var brandNameLabel = new Label{
WidthRequest = 50, // I need these should be dynamic
};
brandNameLabel.SetBinding (Label.TextProperty, "BrandName");
var productCategoryLabel = new Label{
WidthRequest = 150, // I need these should be dynamic
};
productCategoryLabel.SetBinding (Label.TextProperty, "ProductCategory");
var productRangeLabel = new Label{
WidthRequest = 150, // I need these should be dynamic
};
//productRangeLabel.SetBinding (Label.WidthProperty, "2*");
productRangeLabel.SetBinding (Label.TextProperty, "ProductRange");
var packingInnovationLabel = new Label{
WidthRequest = 150, // I need these should be dynamic
};
packingInnovationLabel.SetBinding (Label.TextProperty, "PackingInnovation");
var pricingLabel = new Label {
WidthRequest = 100,
};
pricingLabel.SetBinding (Label.TextProperty, "Pricing");
var stateLabel = new Label{
WidthRequest = 50,
};
stateLabel.SetBinding (Label.TextProperty, "State");
var rowLayout = new StackLayout {
Orientation = StackOrientation.Horizontal,
Children = {
numberLabel,
brandNameLabel,
productCategoryLabel,
productRangeLabel,
packingInnovationLabel,
pricingLabel,
stateLabel
},
};
View = rowLayout;
}
}
public class CompetitiveIntelligencePage : ContentPage
{
public double width { get; set; }
public CompetitiveIntelligencePage ()
{
SizeChanged += (object sender, EventArgs e) => {
width = Width;
var listView = new ListView{
RowHeight = 40,
};
listView.ItemTemplate = new DataTemplate (typeof(CICell));
listView.ItemsSource = CompetitiveIntelligenceList;
var tableHeaderLayout = new StackLayout {
Orientation = StackOrientation.Horizontal,
HeightRequest = 100,
Children = {
new Label{Text = "No",WidthRequest = (0.5*width)/10 },
new Label{Text = "Brand Name", WidthRequest = (1.1*width)/10},
new Label {Text = "Prodcut Category", WidthRequest = (1.9*width)/10},
new Label {Text = "Product Range", WidthRequest = (2*width)/10},
new Label{Text = "Packing Innovation", WidthRequest = (1.5*width)/10},
new Label{Text = "Pricing: Sell Out (Per Price)", WidthRequest = (1.5*width)/10},
new Label{Text = "State (Drop Down Option)",WidthRequest = (1.5*width)/10}
}
};
Content = new StackLayout {
Orientation = StackOrientation.Vertical,
VerticalOptions = LayoutOptions.FillAndExpand,
Children = {headerLayout, tableHeaderLayout, listView }
};
};
}
}