Browse Source

Merge branch 'master' into fix-dev-tools

pull/10369/head
Max Katz 3 years ago
committed by GitHub
parent
commit
2f6b4999d2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/Avalonia.Base/AvaloniaObject.cs
  2. 4
      src/Avalonia.Base/Data/Core/IndexerNodeBase.cs
  3. 4
      src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs
  4. 8
      src/Avalonia.Base/StyledElement.cs
  5. 24
      src/Avalonia.Base/Utilities/WeakEvents.cs
  6. 2
      src/Avalonia.Base/Visual.cs
  7. 10
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
  8. 39
      src/Avalonia.Controls/RelativePanel.AttachedProperties.cs
  9. 4
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/PropertyInfoAccessorFactory.cs

10
src/Avalonia.Base/AvaloniaObject.cs

@ -664,14 +664,12 @@ namespace Avalonia
/// <param name="property">The property that has changed.</param> /// <param name="property">The property that has changed.</param>
/// <param name="oldValue">The old property value.</param> /// <param name="oldValue">The old property value.</param>
/// <param name="newValue">The new property value.</param> /// <param name="newValue">The new property value.</param>
/// <param name="priority">The priority of the binding that produced the value.</param>
protected void RaisePropertyChanged<T>( protected void RaisePropertyChanged<T>(
DirectPropertyBase<T> property, DirectPropertyBase<T> property,
Optional<T> oldValue, T oldValue,
BindingValue<T> newValue, T newValue)
BindingPriority priority = BindingPriority.LocalValue)
{ {
RaisePropertyChanged(property, oldValue, newValue, priority, true); RaisePropertyChanged(property, oldValue, newValue, BindingPriority.LocalValue, true);
} }
/// <summary> /// <summary>
@ -720,7 +718,7 @@ namespace Avalonia
/// <returns> /// <returns>
/// True if the value changed, otherwise false. /// True if the value changed, otherwise false.
/// </returns> /// </returns>
protected bool SetAndRaise<T>(AvaloniaProperty<T> property, ref T field, T value) protected bool SetAndRaise<T>(DirectPropertyBase<T> property, ref T field, T value)
{ {
VerifyAccess(); VerifyAccess();

4
src/Avalonia.Base/Data/Core/IndexerNodeBase.cs

@ -22,7 +22,7 @@ namespace Avalonia.Data.Core
if (target is INotifyPropertyChanged inpc) if (target is INotifyPropertyChanged inpc)
{ {
WeakEvents.PropertyChanged.Subscribe(inpc, this); WeakEvents.ThreadSafePropertyChanged.Subscribe(inpc, this);
} }
ValueChanged(GetValue(target)); ValueChanged(GetValue(target));
@ -39,7 +39,7 @@ namespace Avalonia.Data.Core
if (target is INotifyPropertyChanged inpc) if (target is INotifyPropertyChanged inpc)
{ {
WeakEvents.PropertyChanged.Unsubscribe(inpc, this); WeakEvents.ThreadSafePropertyChanged.Unsubscribe(inpc, this);
} }
} }
} }

4
src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs

@ -160,7 +160,7 @@ namespace Avalonia.Data.Core.Plugins
var inpc = GetReferenceTarget() as INotifyPropertyChanged; var inpc = GetReferenceTarget() as INotifyPropertyChanged;
if (inpc != null) if (inpc != null)
WeakEvents.PropertyChanged.Unsubscribe(inpc, this); WeakEvents.ThreadSafePropertyChanged.Unsubscribe(inpc, this);
} }
private object? GetReferenceTarget() private object? GetReferenceTarget()
@ -185,7 +185,7 @@ namespace Avalonia.Data.Core.Plugins
var inpc = GetReferenceTarget() as INotifyPropertyChanged; var inpc = GetReferenceTarget() as INotifyPropertyChanged;
if (inpc != null) if (inpc != null)
WeakEvents.PropertyChanged.Subscribe(inpc, this); WeakEvents.ThreadSafePropertyChanged.Subscribe(inpc, this);
} }
} }
} }

8
src/Avalonia.Base/StyledElement.cs

@ -524,13 +524,7 @@ namespace Avalonia
NotifyResourcesChanged(); NotifyResourcesChanged();
} }
#nullable disable RaisePropertyChanged(ParentProperty, old, Parent);
RaisePropertyChanged(
ParentProperty,
new Optional<StyledElement>(old),
new BindingValue<StyledElement>(Parent),
BindingPriority.LocalValue);
#nullable enable
} }
} }

24
src/Avalonia.Base/Utilities/WeakEvents.cs

@ -2,6 +2,7 @@ using System;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.ComponentModel; using System.ComponentModel;
using System.Windows.Input; using System.Windows.Input;
using Avalonia.Threading;
namespace Avalonia.Utilities; namespace Avalonia.Utilities;
@ -20,15 +21,30 @@ public class WeakEvents
}); });
/// <summary> /// <summary>
/// Represents PropertyChanged event from <see cref="INotifyPropertyChanged"/> /// Represents PropertyChanged event from <see cref="INotifyPropertyChanged"/> with auto-dispatching to the UI thread
/// </summary> /// </summary>
public static readonly WeakEvent<INotifyPropertyChanged, PropertyChangedEventArgs> public static readonly WeakEvent<INotifyPropertyChanged, PropertyChangedEventArgs>
PropertyChanged = WeakEvent.Register<INotifyPropertyChanged, PropertyChangedEventArgs>( ThreadSafePropertyChanged = WeakEvent.Register<INotifyPropertyChanged, PropertyChangedEventArgs>(
(s, h) => (s, h) =>
{ {
PropertyChangedEventHandler handler = (_, e) => h(s, e); bool unsubscribed = false;
PropertyChangedEventHandler handler = (_, e) =>
{
if (Dispatcher.UIThread.CheckAccess())
h(s, e);
else
Dispatcher.UIThread.Post(() =>
{
if (!unsubscribed)
h(s, e);
});
};
s.PropertyChanged += handler; s.PropertyChanged += handler;
return () => s.PropertyChanged -= handler; return () =>
{
unsubscribed = true;
s.PropertyChanged -= handler;
};
}); });

2
src/Avalonia.Base/Visual.cs

@ -573,7 +573,7 @@ namespace Avalonia
/// <param name="newParent">The new visual parent.</param> /// <param name="newParent">The new visual parent.</param>
protected virtual void OnVisualParentChanged(Visual? oldParent, Visual? newParent) protected virtual void OnVisualParentChanged(Visual? oldParent, Visual? newParent)
{ {
RaisePropertyChanged(VisualParentProperty, oldParent, newParent, BindingPriority.LocalValue); RaisePropertyChanged(VisualParentProperty, oldParent, newParent);
} }
internal override ParametrizedLogger? GetBindingWarningLogger( internal override ParametrizedLogger? GetBindingWarningLogger(

10
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@ -345,10 +345,7 @@ namespace Avalonia.Controls.Primitives
if (_oldSelectedItems != SelectedItems) if (_oldSelectedItems != SelectedItems)
{ {
RaisePropertyChanged( RaisePropertyChanged(SelectedItemsProperty, _oldSelectedItems, SelectedItems);
SelectedItemsProperty,
new Optional<IList?>(_oldSelectedItems),
new BindingValue<IList?>(SelectedItems));
_oldSelectedItems = SelectedItems; _oldSelectedItems = SelectedItems;
} }
} }
@ -909,10 +906,7 @@ namespace Avalonia.Controls.Primitives
else if (e.PropertyName == nameof(InternalSelectionModel.WritableSelectedItems) && else if (e.PropertyName == nameof(InternalSelectionModel.WritableSelectedItems) &&
_oldSelectedItems != (Selection as InternalSelectionModel)?.SelectedItems) _oldSelectedItems != (Selection as InternalSelectionModel)?.SelectedItems)
{ {
RaisePropertyChanged( RaisePropertyChanged(SelectedItemsProperty, _oldSelectedItems, SelectedItems);
SelectedItemsProperty,
new Optional<IList?>(_oldSelectedItems),
new BindingValue<IList?>(SelectedItems));
_oldSelectedItems = SelectedItems; _oldSelectedItems = SelectedItems;
} }
else if (e.PropertyName == nameof(ISelectionModel.Source)) else if (e.PropertyName == nameof(ISelectionModel.Source))

39
src/Avalonia.Controls/RelativePanel.AttachedProperties.cs

@ -1,37 +1,30 @@
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.Threading;
namespace Avalonia.Controls namespace Avalonia.Controls
{ {
public partial class RelativePanel public partial class RelativePanel
{ {
private static void OnAlignPropertiesChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
{
if (d is Layoutable layoutable && layoutable.Parent is Layoutable layoutableParent)
{
layoutableParent.InvalidateArrange();
}
}
static RelativePanel() static RelativePanel()
{ {
ClipToBoundsProperty.OverrideDefaultValue<RelativePanel>(true); ClipToBoundsProperty.OverrideDefaultValue<RelativePanel>(true);
AboveProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AffectsParentArrange<RelativePanel>(
AlignBottomWithPanelProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignLeftWithPanelProperty, AlignLeftWithProperty, LeftOfProperty,
AlignBottomWithProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignRightWithPanelProperty, AlignRightWithProperty, RightOfProperty,
AlignHorizontalCenterWithPanelProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignTopWithPanelProperty, AlignTopWithProperty, AboveProperty,
AlignHorizontalCenterWithProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignBottomWithPanelProperty, AlignBottomWithProperty, BelowProperty,
AlignLeftWithPanelProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignHorizontalCenterWithPanelProperty, AlignHorizontalCenterWithProperty,
AlignLeftWithProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignVerticalCenterWithPanelProperty, AlignVerticalCenterWithProperty);
AlignRightWithPanelProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged);
AlignRightWithProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AffectsParentMeasure<RelativePanel>(
AlignTopWithPanelProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignLeftWithPanelProperty, AlignLeftWithProperty, LeftOfProperty,
AlignTopWithProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignRightWithPanelProperty, AlignRightWithProperty, RightOfProperty,
AlignVerticalCenterWithPanelProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignTopWithPanelProperty, AlignTopWithProperty, AboveProperty,
AlignVerticalCenterWithProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignBottomWithPanelProperty, AlignBottomWithProperty, BelowProperty,
BelowProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignHorizontalCenterWithPanelProperty, AlignHorizontalCenterWithProperty,
LeftOfProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged); AlignVerticalCenterWithPanelProperty, AlignVerticalCenterWithProperty);
RightOfProperty.Changed.AddClassHandler<Layoutable>(OnAlignPropertiesChanged);
} }
/// <summary> /// <summary>

4
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/PropertyInfoAccessorFactory.cs

@ -121,7 +121,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings
{ {
if (_reference.TryGetTarget(out var o) && o is INotifyPropertyChanged inpc) if (_reference.TryGetTarget(out var o) && o is INotifyPropertyChanged inpc)
{ {
WeakEvents.PropertyChanged.Unsubscribe(inpc, this); WeakEvents.ThreadSafePropertyChanged.Unsubscribe(inpc, this);
} }
} }
@ -138,7 +138,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings
private void SubscribeToChanges() private void SubscribeToChanges()
{ {
if (_reference.TryGetTarget(out var o) && o is INotifyPropertyChanged inpc) if (_reference.TryGetTarget(out var o) && o is INotifyPropertyChanged inpc)
WeakEvents.PropertyChanged.Subscribe(inpc, this); WeakEvents.ThreadSafePropertyChanged.Subscribe(inpc, this);
} }
} }

Loading…
Cancel
Save