I have a page which has 3 static questions, followed by a Listview which is binded to a dynamic list of questions (number of questions can change meaning the height of the listview needs to change)
Currently the listview is a static height. I need the listview to be dynamic and change height based on the number of questions.
The listview is in a scrollable view, if i take it out I end up having two scrollable sections within the page which I do not want.
How do I get the listview to expand as needed? I'm happy to use another control if more suitable. I'd like a solution which uses the MVVM framework if possible.
Below is the XAML for the listview:
<ListView ItemsSource="{Binding AdditionalFields}" RowHeight="75" BackgroundColor="Green" VerticalOptions="FillAndExpand" HasUnevenRows="True">
<ListView.ItemTemplate >
<DataTemplate>
<ViewCell>
<ContentView BackgroundColor="Yellow">
<Grid>
<Image Source="{Binding ProductImage}"/> <!--Image not showing-->
<Label Text="{Binding DefaultName}" Style="{DynamicResource labelInformationStyle}" HorizontalOptions="StartAndExpand" Margin="15, 10, 0, 0"/>
<controls:AdditionalFieldControl />
</Grid>
</ContentView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Here is my AdditionalFieldControl constructor (which allows the user to enter an answer to the question) which is used in the snippet above (I know the fields aren't binded yet).
public AdditionalFieldControl()
{
//Set the the entry to fill and expand
this.HorizontalOptions = new LayoutOptions() { Alignment = LayoutAlignment.Start, Expands = true, };
_entry = new Entry()
{
Placeholder = "Type input ...",// this.TextPlaceholder,
PlaceholderColor = Xamarin.Forms.Color.Gray,
Text = this.Text,
TextColor = Xamarin.Forms.Color.Black,
FontAttributes = FontAttributes.None,
HeightRequest = 200,
Margin = new Thickness(15, 25, 0, 0)
};
//add the entry to the stack layout
this.Children.Add(_entry);
}
Please let me know if you need anymore information, thanks in advance for any help.
I'm debugging on a Samsung Galaxy S5 mini
Android version: 6.0.1