diff --git a/Source/OxyPlot.Avalonia/Plot.Properties.cs b/Source/OxyPlot.Avalonia/Plot.Properties.cs
index 9d900cf..cec7f79 100644
--- a/Source/OxyPlot.Avalonia/Plot.Properties.cs
+++ b/Source/OxyPlot.Avalonia/Plot.Properties.cs
@@ -95,7 +95,7 @@ public partial class Plot
///
/// Identifies the dependency property.
///
- public static readonly StyledProperty PlotAreaBackgroundProperty = AvaloniaProperty.Register(nameof(PlotAreaBackground), null);
+ public static readonly StyledProperty PlotAreaBackgroundProperty = AvaloniaProperty.Register(nameof(PlotAreaBackground), null);
///
/// Identifies the dependency property.
@@ -140,7 +140,7 @@ public partial class Plot
///
/// Identifies the dependency property.
///
- public static readonly StyledProperty TitleAlignmentProperty = AvaloniaProperty.Register(nameof(TitleHorizontalAlignment), TitleHorizontalAlignment.CenteredWithinPlotArea);
+ public static readonly StyledProperty TitleHorizontalAlignmentProperty = AvaloniaProperty.Register(nameof(TitleHorizontalAlignment), TitleHorizontalAlignment.CenteredWithinPlotArea);
///
/// Identifies the dependency property.
@@ -204,7 +204,7 @@ static Plot()
SubtitleFontWeightProperty.Changed.AddClassHandler(AppearanceChanged);
SubtitleProperty.Changed.AddClassHandler(AppearanceChanged);
TextColorProperty.Changed.AddClassHandler(AppearanceChanged);
- TitleAlignmentProperty.Changed.AddClassHandler(AppearanceChanged);
+ TitleHorizontalAlignmentProperty.Changed.AddClassHandler(AppearanceChanged);
TitleFontProperty.Changed.AddClassHandler(AppearanceChanged);
TitleFontSizeProperty.Changed.AddClassHandler(AppearanceChanged);
TitleFontWeightProperty.Changed.AddClassHandler(AppearanceChanged);
@@ -426,7 +426,7 @@ public Color SubtitleColor
/// Gets or sets the background brush of the Plot area.
///
/// The brush.
- public Brush PlotAreaBackground
+ public IBrush PlotAreaBackground
{
get
{
@@ -640,12 +640,12 @@ public TitleHorizontalAlignment TitleHorizontalAlignment
{
get
{
- return GetValue(TitleAlignmentProperty);
+ return GetValue(TitleHorizontalAlignmentProperty);
}
set
{
- SetValue(TitleAlignmentProperty, value);
+ SetValue(TitleHorizontalAlignmentProperty, value);
}
}
diff --git a/Source/OxyPlot.Avalonia/Plot.cs b/Source/OxyPlot.Avalonia/Plot.cs
index abab5a3..595292c 100644
--- a/Source/OxyPlot.Avalonia/Plot.cs
+++ b/Source/OxyPlot.Avalonia/Plot.cs
@@ -14,6 +14,7 @@ namespace OxyPlot.Avalonia
using global::Avalonia.Controls;
using global::Avalonia.LogicalTree;
using global::Avalonia.VisualTree;
+ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
@@ -93,15 +94,16 @@ public override IPlotController ActualController
/// Updates the model. If Model==null, an internal model will be created. The ActualModel.Update will be called (updates all series data).
///
/// if set to true , all data collections will be updated.
- protected new void UpdateModel(bool updateData = true)
+ protected override void UpdateModel(bool updateData = true)
{
+ // The method is virtual, so InvalidatePlot also ends up here (including from InvalidateFlag
+ // and from the axes): without synchronization, in-place edits of the wrappers would not reach the model.
SynchronizeProperties();
SynchronizeSeries();
SynchronizeAxes();
SynchronizeAnnotations();
SynchronizeLegends();
- // TODO: does this achieve anything? we always call InvalidatePlot after UpdateModel
base.UpdateModel(updateData);
}
@@ -110,22 +112,19 @@ public override IPlotController ActualController
///
protected void OnAppearanceChanged()
{
- UpdateModel(false);
InvalidatePlot(false);
}
void IPlot.ElementAppearanceChanged(object element)
{
// TODO: determine type of element to perform a more fine-grained update
- this.UpdateModel(false);
- base.InvalidatePlot(false);
+ InvalidatePlot(false);
}
void IPlot.ElementDataChanged(object element)
{
// TODO: determine type of element to perform a more fine-grained update
- this.UpdateModel(true);
- base.InvalidatePlot(true);
+ InvalidatePlot(true);
}
@@ -175,6 +174,19 @@ private void OnSeriesChanged(object sender, NotifyCollectionChangedEventArgs e)
/// The instance containing the event data.
private void SyncLogicalTree(NotifyCollectionChangedEventArgs e)
{
+ // Reset (which is Clear) does not provide OldItems, while Move and Replace send
+ // the same element in both NewItems and OldItems. In these cases the per-item logic
+ // below leaves garbage in the tree, clears the parent or fails on re-adding,
+ // so the tree is rebuilt completely.
+ if (e.Action == NotifyCollectionChangedAction.Reset
+ || e.Action == NotifyCollectionChangedAction.Move
+ || e.Action == NotifyCollectionChangedAction.Replace)
+ {
+ RebuildTreeChildren();
+ OnElementsChanged();
+ return;
+ }
+
// In order to get DataContext and binding to work with the series, axes and annotations
// we add the items to the logical tree
if (e.NewItems != null)
@@ -201,7 +213,70 @@ private void SyncLogicalTree(NotifyCollectionChangedEventArgs e)
}
}
- this.OnAppearanceChanged();
+ OnElementsChanged();
+ }
+
+ ///
+ /// Updates the model after the set of series, axes, annotations or legends has changed.
+ /// This is a data update: the core loads the series points and computes the axis ranges
+ /// only during it, otherwise an added series stays empty and the axes have no range.
+ ///
+ private void OnElementsChanged()
+ {
+ InvalidatePlot(true);
+ }
+
+ ///
+ /// Brings the logical and visual trees in line with the collections of the plot.
+ /// Elements of the control template are not touched: they are also in the visual tree,
+ /// and removing them would break rendering permanently.
+ ///
+ private void RebuildTreeChildren()
+ {
+ var expected = new HashSet