Код: Выделить всё
public class PCollection : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
public ObservableCollection
Points { get; set; }
public PCollection()
{
Points = new(Database.GetPoints());
}
public void NotifyPropertyChanged(string info)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
}
}
< /code>
(от полилины, связанной с наблюдением, не обновляется)
(Database.GetPoints()
и уведомляя об изменениях, вызывая функцию экземпляра Pcollection NotifyPropertychange, но, опять же, это не влияет на полилин после того, как страница изначально загружается. > Canvasview.axaml
Код: Выделить всё
Код: Выделить всё
public class CanvasViewModel : ViewModelBase
{
public ObservableCollection Points { get; };
public CanvasViewModel()
{
Points = new(Database.GetPoints());
}
public void DrawLine()
{
System.Random rand = new();
Point p = new(rand.Next(101), rand.Next(101));
Points.Add(p);
this.RaisePropertyChanged(nameof(Points));
System.Diagnostics.Debug.WriteLine(p); // shows that the point is actually created and added to the collection
}
}
< /code>
(Database.GetPoints()
Подробнее здесь: https://stackoverflow.com/questions/680 ... n-avalonia