<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class=".Views.MainPageView"
Title="" Icon="menu_icon.png">
<MasterDetailPage.Detail>
<ContentPage Title="title" >
<Grid RowSpacing="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="20" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Text="{Binding ErrorText}" Grid.Row="2" Grid.ColumnSpan="2" Grid.Column="0" TextColor="Red" FontSize="8" LineBreakMode="WordWrap"/>
<ListView ItemsSource="{Binding Grouped}" Grid.Row="3" Grid.ColumnSpan="2"
Grid.Column="0" IsGroupingEnabled="True" GroupDisplayBinding="{Binding Key}" HasUnevenRows="True"
GroupShortNameBinding="{Binding Key}" IsPullToRefreshEnabled="True" RefreshCommand="{Binding RefreshCommand}"
IsRefreshing="{Binding IsBusy, Mode=OneWay}">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell Height="25">
<StackLayout VerticalOptions="FillAndExpand" Padding="5">
<Label Text="{Binding Key}" TextColor="White" VerticalOptions="Center" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid RowSpacing="0" Padding="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Text="{Binding name}" FontSize="12" FontAttributes="Bold" Grid.Row="0" Grid.Column="0" />
<Label Text="{Binding date, StringFormat='{}{0:dd-MM-yyyy}'}" Grid.Row="0" FontSize="10" Grid.Column="1" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ContentPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
namespace.ViewModel
{
public class MainViewModel : ViewModelBase, INotifyPropertyChanged
{
private readonly INavigationService _navigationService
public MainViewModel(INavigationService navigationservice)
{
Messenger.Default.Register<RefreshMessage>(this, msg => RefreshData());
_navigationService = navigationservice;
}
private async void RefreshData()
{
ClientReturn response = await client.GetClients();
Clients = new ObservableCollection<Client>(response.Clients);
var sorted = from singleclient in Clients
orderby singleclient.ClientName
group singleclient by singleclient.NameSort into clientGroup
select new Grouping<string, Client>(clientGroup.Key, clientGroup);
Grouped = new ObservableCollection<Grouping<string, Client>>(sorted);
}
private RelayCommand _refreshCommand;
public RelayCommand RefreshCommand
{
get
{
return _refreshCommand ?? (_refreshCommand = new RelayCommand(() => { RefreshData(); }));
}
}
public ObservableCollection<Client> Clients { get; set; }
public ObservableCollection<Grouping<string, Client>> ClientsGrouped { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyname)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
}
}
}
}
The problem is my normal bindings are updated, hoever the listview isn't updated at all, while the ClientsGrouped is indeed updated upon object inspection.
I've also updated it with the VM now, however please note that I only posted the relevant information. Things like error handling and else have been omitted.