-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
226 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Uno.UI.RuntimeTests/Tests/TemplatedParent/Setup/BehaviorSetup.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Page x:Class="Uno.UI.RuntimeTests.Tests.TemplatedParent.Setup.BehaviorSetup" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:Uno.UI.RuntimeTests.Tests.TemplatedParent.Setup"> | ||
|
||
<Button Tag="Asd"> | ||
<Button.Template> | ||
<ControlTemplate TargetType="Button"> | ||
<Grid x:Name="RootGrid"> | ||
<local:Interaction.Behaviors> | ||
<local:LegacyDOBehavior TestValue="{TemplateBinding Tag}" /> | ||
<local:NonLegacyDOBehavior TestValue="{TemplateBinding Tag}" /> | ||
</local:Interaction.Behaviors> | ||
</Grid> | ||
</ControlTemplate> | ||
</Button.Template> | ||
</Button> | ||
|
||
</Page> |
101 changes: 101 additions & 0 deletions
101
src/Uno.UI.RuntimeTests/Tests/TemplatedParent/Setup/BehaviorSetup.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Uno.UI.DataBinding; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.TemplatedParent.Setup; | ||
|
||
public sealed partial class BehaviorSetup : Page | ||
{ | ||
public BehaviorSetup() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
|
||
public sealed class Interaction | ||
{ | ||
#region DependencyProperty: Behaviors | ||
|
||
public static DependencyProperty BehaviorsProperty { get; } = DependencyProperty.RegisterAttached( | ||
"Behaviors", | ||
typeof(BehaviorCollection), | ||
typeof(Interaction), | ||
new PropertyMetadata(null, OnBehaviorsChanged)); | ||
|
||
public static BehaviorCollection GetBehaviors(DependencyObject obj) => GetBehaviorsOverride(obj); | ||
public static void SetBehaviors(DependencyObject obj, BehaviorCollection value) => obj.SetValue(BehaviorsProperty, value); | ||
|
||
#endregion | ||
|
||
private static BehaviorCollection GetBehaviorsOverride(DependencyObject obj) | ||
{ | ||
var value = (BehaviorCollection)obj.GetValue(BehaviorsProperty); | ||
if (value is null) | ||
{ | ||
obj.SetValue(BehaviorsProperty, value = new BehaviorCollection()); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
private static void OnBehaviorsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) | ||
{ | ||
if (e.NewValue is BehaviorCollection collection) | ||
{ | ||
collection.AssociatedObject = sender; | ||
} | ||
} | ||
} | ||
public sealed class BehaviorCollection : DependencyObjectCollection | ||
{ | ||
public DependencyObject AssociatedObject { get; set; } | ||
} | ||
|
||
public interface IBehavior { } | ||
|
||
public partial class LegacyDOBehavior : DependencyObject, IBehavior, INotTemplatedParentProvider | ||
{ | ||
#region DependencyProperty: TestValue | ||
|
||
public static DependencyProperty TestValueProperty { get; } = DependencyProperty.Register( | ||
nameof(TestValue), | ||
typeof(object), | ||
typeof(LegacyDOBehavior), | ||
new PropertyMetadata(default(object), OnTestValueChanged)); | ||
|
||
public object TestValue | ||
{ | ||
get => (object)GetValue(TestValueProperty); | ||
set => SetValue(TestValueProperty, value); | ||
} | ||
|
||
#endregion | ||
|
||
private static void OnTestValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) | ||
{ | ||
} | ||
} | ||
public partial class NonLegacyDOBehavior : DependencyObject, IBehavior | ||
{ | ||
#region DependencyProperty: TestValue | ||
|
||
public static DependencyProperty TestValueProperty { get; } = DependencyProperty.Register( | ||
nameof(TestValue), | ||
typeof(object), | ||
typeof(NonLegacyDOBehavior), | ||
new PropertyMetadata(default(object), OnTestValueChanged)); | ||
|
||
public object TestValue | ||
{ | ||
get => (object)GetValue(TestValueProperty); | ||
set => SetValue(TestValueProperty, value); | ||
} | ||
|
||
#endregion | ||
|
||
private static void OnTestValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters