public class StudyParameterGroupModel : List<StudyParameterGroupOptionsModel> { public string GroupDisplayText { get; set; } public List<StudyParameterGroupOptionsModel> DiseaseOptions { get; set; } } public class StudyParameterGroupOptionsModel { public string ParameterDisplayText { get; set; } public int SubDiseaseId { get; set; } public bool IsSelected { get; set; } }
public List<StudyParameterGroupModel> _studyParameterGroupList; public List<StudyParameterGroupModel> StudyParameterGroupList { get { return _studyParameterGroupList; } set { _studyParameterGroupList = value; OnPropertyChanged("StudyParameterGroupList"); } } IRestResponse<List<StudyParameterGroupDTO>> responseDto = client.Execute<List<StudyParameterGroupDTO>>(request); if (response.StatusCode == HttpStatusCode.OK) { StudyParameterGroupList = responseDto.Data.Select(resp => new StudyParameterGroupModel() GroupDisplayText = resp.DisplayText, DiseaseOptions = resp.Options .Select(opt => new StudyParameterGroupOptionsModel() { ParameterDisplayText = opt.DisplayText, SubDiseaseId = opt.SubDiseaseId, }).ToList(), }).ToList(); }
~<ListView x:Name="list" ItemsSource="{Binding StudyParameterGroupList, Mode=TwoWay}" IsGroupingEnabled="True" GroupDisplayBinding="{Binding GroupName}" HasUnevenRows="True"> <ListView.GroupHeaderTemplate> <DataTemplate> <ViewCell Height="25"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Label Grid.Row="0" Text="{Binding GroupDisplayText }" FontSize="Medium" FontFamily="{StaticResource RegularFont}" TextColor="White" VerticalOptions="Center"/> <Label VerticalTextAlignment="Start" VerticalOptions="Start" HorizontalOptions="Start" Grid.Column="1" Text="*" TextColor="Red" FontSize="Medium" FontFamily="{StaticResource RegularFont}" /> </Grid> </ViewCell> </DataTemplate> </ListView.GroupHeaderTemplate> <ListView.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <telerikPrimitives:RadCheckBox x:Name="checkbox" Grid.Row="0" IsChecked="{Binding IsSelected, Mode=TwoWay}" /> <Label Text="{Binding Parameter, Mode=TwoWay}" VerticalTextAlignment="Center" VerticalOptions="Center" HorizontalOptions="Center" Grid.Column="1" FontSize="Medium" FontFamily="{StaticResource RegularFont}"/> </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView>~
Data is in the StudyParameterGroupList, but not appearing in view.
Answers
Each ListView Item has a BindingContext dynamically assigned to.
and is accessible like this :
var context = object.BindingContext as ModelClass;
and you could use the values in it like this:
var p = (object.BindingContext as ModelClass).Property;
good luck
Love Xamarin :
Try to set
ListView.ItemsSource
in code in Page.Doing it in MVVM
Could you provide the complete code used in the page ?
namespace Cureitt.Mobile.Patient.ViewModels
{
public class ProfileViewModel : ValidationBase, INotifyPropertyChanged
{
private Page _page;
}
It's better to upload a mini, basic sample project on forum , we need to reproduce the issue for further troubleshooting.