Hi Rainer-M,
Welcome to our Microsoft Q&A platform!
In my test, the event "PropertyChanged" in your project has never been triggered. So I directly modified ObsOffers in "DoRefresh". And everything works fine, the UI updates in succeed.
It seems like you want to update the collectionview with new items. Here is my way to update the CollectionView and it works fine in both Android and iOS.
xaml:
<StackLayout Padding="0,40,0,0">
<Button Text="Update" Command="{Binding UpdateCommand}"/>
<ScrollView VerticalScrollBarVisibility="Never">
<CollectionView
BackgroundColor="Red"
ItemsSource="{Binding ObsOffers}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding ID}" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ScrollView>
</StackLayout>
xaml.cs:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
this.BindingContext = new TestViewModel();
}
}
And define the viewmodel in "ClassLibrary" project.
public class TestViewModel : INotifyPropertyChanged
{
public ICommand UpdateCommand { get; }
public string Text { get; set; }
string state;
public string Stata
{
get => state;
set
{
state = value;
OnPropertyChanged("State");
}
}
public ObservableCollection<Offer> ObsOffers { get; } = new ObservableCollection<Offer>();
public TestViewModel()
{
for (int i = 0; i < 10; i++)
{
ObsOffers.Add(new Offer { ID = "ID" + i });
}
UpdateCommand = new Command(Update);
}
void Update()
{
Stata = "stata changed";
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
if(propertyName == "State")
{
Console.WriteLine("stata changed");
ObsOffers.Clear();
for (int i = 0; i < 10; i++)
{
ObsOffers.Add(new Offer { ID = "NewID" + i });
}
}
}
}
Regards,
Kyle
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.