committed by
GitHub
35 changed files with 383 additions and 420 deletions
@ -0,0 +1,13 @@ |
|||
namespace Avalonia |
|||
{ |
|||
/// <summary>
|
|||
/// Defines an element with a data context that can be used for binding.
|
|||
/// </summary>
|
|||
public interface IDataContextProvider : IAvaloniaObject |
|||
{ |
|||
/// <summary>
|
|||
/// Gets or sets the element's data context.
|
|||
/// </summary>
|
|||
object DataContext { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
using Avalonia.Data; |
|||
using BenchmarkDotNet.Attributes; |
|||
|
|||
namespace Avalonia.Benchmarks.Data |
|||
{ |
|||
[MemoryDiagnoser, InProcess] |
|||
public class BindingsBenchmark |
|||
{ |
|||
[Benchmark] |
|||
public void TwoWayBinding_Via_Binding() |
|||
{ |
|||
var instance = new TestClass(); |
|||
|
|||
var binding = new Binding(nameof(TestClass.BoundValue), BindingMode.TwoWay) |
|||
{ |
|||
Source = instance |
|||
}; |
|||
|
|||
instance.Bind(TestClass.IntValueProperty, binding); |
|||
} |
|||
|
|||
[Benchmark] |
|||
public void UpdateTwoWayBinding_Via_Binding() |
|||
{ |
|||
var instance = new TestClass(); |
|||
|
|||
var binding = new Binding(nameof(TestClass.BoundValue), BindingMode.TwoWay) |
|||
{ |
|||
Source = instance |
|||
}; |
|||
|
|||
instance.Bind(TestClass.IntValueProperty, binding); |
|||
for (int i = 0; i < 60; i++) |
|||
{ |
|||
instance.IntValue = i; |
|||
} |
|||
} |
|||
private class TestClass : AvaloniaObject |
|||
{ |
|||
public static readonly StyledProperty<int> IntValueProperty = |
|||
AvaloniaProperty.Register<TestClass, int>(nameof(IntValue)); |
|||
|
|||
public static readonly StyledProperty<int> BoundValueProperty = |
|||
AvaloniaProperty.Register<TestClass, int>(nameof(BoundValue)); |
|||
|
|||
public int IntValue |
|||
{ |
|||
get => GetValue(IntValueProperty); |
|||
set => SetValue(IntValueProperty, value); |
|||
} |
|||
|
|||
public int BoundValue |
|||
{ |
|||
get => GetValue(BoundValueProperty); |
|||
set => SetValue(BoundValueProperty, value); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,83 +0,0 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Reactive; |
|||
using Avalonia.Collections; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Data; |
|||
|
|||
namespace Avalonia.Styling.UnitTests |
|||
{ |
|||
public class TestControlBase : IStyleable |
|||
{ |
|||
public TestControlBase() |
|||
{ |
|||
Classes = new Classes(); |
|||
SubscribeCheckObservable = new TestObservable(); |
|||
} |
|||
|
|||
#pragma warning disable CS0067 // Event not used
|
|||
public event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged; |
|||
public event EventHandler<AvaloniaPropertyChangedEventArgs> InheritablePropertyChanged; |
|||
#pragma warning restore CS0067
|
|||
|
|||
public string Name { get; set; } |
|||
|
|||
public virtual Classes Classes { get; set; } |
|||
|
|||
public Type StyleKey => GetType(); |
|||
|
|||
public TestObservable SubscribeCheckObservable { get; private set; } |
|||
|
|||
public ITemplatedControl TemplatedParent |
|||
{ |
|||
get; |
|||
set; |
|||
} |
|||
|
|||
IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes; |
|||
|
|||
IObservable<IStyleable> IStyleable.StyleDetach { get; } |
|||
|
|||
public object GetValue(AvaloniaProperty property) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public T GetValue<T>(AvaloniaProperty<T> property) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public void SetValue(AvaloniaProperty property, object value, BindingPriority priority) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public void SetValue<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public bool IsAnimating(AvaloniaProperty property) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public bool IsSet(AvaloniaProperty property) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public IDisposable Bind(AvaloniaProperty property, IObservable<object> source, BindingPriority priority = BindingPriority.LocalValue) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public IDisposable Bind<T>(AvaloniaProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,81 +0,0 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using System.Reactive; |
|||
using Avalonia.Collections; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Data; |
|||
|
|||
namespace Avalonia.Styling.UnitTests |
|||
{ |
|||
public abstract class TestTemplatedControl : ITemplatedControl, IStyleable |
|||
{ |
|||
public event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged; |
|||
public event EventHandler<AvaloniaPropertyChangedEventArgs> InheritablePropertyChanged; |
|||
|
|||
public abstract Classes Classes |
|||
{ |
|||
get; |
|||
} |
|||
|
|||
public abstract string Name |
|||
{ |
|||
get; |
|||
} |
|||
|
|||
public abstract Type StyleKey |
|||
{ |
|||
get; |
|||
} |
|||
|
|||
public abstract ITemplatedControl TemplatedParent |
|||
{ |
|||
get; |
|||
} |
|||
|
|||
IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes; |
|||
|
|||
IObservable<IStyleable> IStyleable.StyleDetach { get; } |
|||
|
|||
public object GetValue(AvaloniaProperty property) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public T GetValue<T>(AvaloniaProperty<T> property) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public void SetValue(AvaloniaProperty property, object value, BindingPriority priority) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public void SetValue<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public IDisposable Bind(AvaloniaProperty property, IObservable<object> source, BindingPriority priority = BindingPriority.LocalValue) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public IDisposable Bind<T>(AvaloniaProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public bool IsAnimating(AvaloniaProperty property) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public bool IsSet(AvaloniaProperty property) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue