Browse Source

Merge branch 'master' into opengl-warning-fixes

pull/10372/head
Max Katz 3 years ago
committed by GitHub
parent
commit
3e31b549cf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/Avalonia.Base/Data/Core/IndexerNodeBase.cs
  2. 4
      src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs
  3. 24
      src/Avalonia.Base/Utilities/WeakEvents.cs
  4. 39
      src/Avalonia.Controls/RelativePanel.AttachedProperties.cs
  5. 2
      src/Avalonia.Diagnostics/Diagnostics/Controls/FilterTextBox.axaml
  6. 4
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlLayoutViewModel.cs
  7. 4
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/CompiledBindings/PropertyInfoAccessorFactory.cs

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);
} }
} }
} }

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;
};
}); });

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>

2
src/Avalonia.Diagnostics/Diagnostics/Controls/FilterTextBox.axaml

@ -16,6 +16,8 @@
<StackPanel Orientation="Horizontal" Spacing="1"> <StackPanel Orientation="Horizontal" Spacing="1">
<Button Margin="0,0,2,0" <Button Margin="0,0,2,0"
Classes="textBoxClearButton" Classes="textBoxClearButton"
Theme="{StaticResource SimpleTextBoxClearButtonTheme}"
Focusable="False"
ToolTip.Tip="Clear" ToolTip.Tip="Clear"
Cursor="Hand" Cursor="Hand"
Command="{Binding $parent[TextBox].Clear}" Command="{Binding $parent[TextBox].Clear}"

4
src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlLayoutViewModel.cs

@ -103,13 +103,13 @@ namespace Avalonia.Diagnostics.ViewModels
public HorizontalAlignment HorizontalAlignment public HorizontalAlignment HorizontalAlignment
{ {
get => _horizontalAlignment; get => _horizontalAlignment;
private set => RaiseAndSetIfChanged(ref _horizontalAlignment, value); set => RaiseAndSetIfChanged(ref _horizontalAlignment, value);
} }
public VerticalAlignment VerticalAlignment public VerticalAlignment VerticalAlignment
{ {
get => _verticalAlignment; get => _verticalAlignment;
private set => RaiseAndSetIfChanged(ref _verticalAlignment, value); set => RaiseAndSetIfChanged(ref _verticalAlignment, value);
} }
public bool HasPadding { get; } public bool HasPadding { get; }

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