-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # CommunityToolkit.WinUI.UI.Behaviors/Viewport/ViewportBehavior.Properties.cs # UITests/UITests.App/UITests.App.csproj
- Loading branch information
Showing
13 changed files
with
334 additions
and
86 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
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
106 changes: 106 additions & 0 deletions
106
CommunityToolkit.WinUI.UI.Behaviors/Viewport/ViewportBehavior.Properties.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,106 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.Xaml.Interactivity; | ||
|
||
namespace CommunityToolkit.WinUI.UI.Behaviors | ||
{ | ||
/// <summary> | ||
/// A class for listening to an element enter or exit the ScrollViewer viewport | ||
/// </summary> | ||
public partial class ViewportBehavior | ||
{ | ||
/// <summary> | ||
/// The IsFullyInViewport value of the associated element | ||
/// </summary> | ||
public static readonly DependencyProperty IsFullyInViewportProperty = | ||
DependencyProperty.Register(nameof(IsFullyInViewport), typeof(bool), typeof(ViewportBehavior), new PropertyMetadata(default(bool), OnIsFullyInViewportChanged)); | ||
|
||
/// <summary> | ||
/// The IsInViewport value of the associated element | ||
/// </summary> | ||
public static readonly DependencyProperty IsInViewportProperty = | ||
DependencyProperty.Register(nameof(IsInViewport), typeof(bool), typeof(ViewportBehavior), new PropertyMetadata(default(bool), OnIsInViewportChanged)); | ||
|
||
/// <summary> | ||
/// The IsAlwaysOn value of the associated element | ||
/// </summary> | ||
public static readonly DependencyProperty IsAlwaysOnProperty = | ||
DependencyProperty.Register(nameof(IsAlwaysOn), typeof(bool), typeof(ViewportBehavior), new PropertyMetadata(default(bool))); | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether this behavior will remain attached after the associated element enters the viewport. When false, the behavior will remove itself after entering. | ||
/// </summary> | ||
public bool IsAlwaysOn | ||
{ | ||
get { return (bool)GetValue(IsAlwaysOnProperty); } | ||
set { SetValue(IsAlwaysOnProperty, value); } | ||
} | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether associated element is fully in the ScrollViewer viewport | ||
/// </summary> | ||
public bool IsFullyInViewport | ||
{ | ||
get { return (bool)GetValue(IsFullyInViewportProperty); } | ||
private set { SetValue(IsFullyInViewportProperty, value); } | ||
} | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether associated element is in the ScrollViewer viewport | ||
/// </summary> | ||
public bool IsInViewport | ||
{ | ||
get { return (bool)GetValue(IsInViewportProperty); } | ||
private set { SetValue(IsInViewportProperty, value); } | ||
} | ||
|
||
/// <summary> | ||
/// Event tracking when the object is fully within the viewport or not | ||
/// </summary> | ||
/// <param name="d">DependencyObject</param> | ||
/// <param name="e">EventArgs</param> | ||
private static void OnIsFullyInViewportChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
var obj = (ViewportBehavior)d; | ||
var value = (bool)e.NewValue; | ||
|
||
if (value) | ||
{ | ||
obj.EnteredViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty); | ||
|
||
if (!obj.IsAlwaysOn) | ||
{ | ||
Interaction.GetBehaviors(obj.AssociatedObject).Remove(obj); | ||
} | ||
} | ||
else | ||
{ | ||
obj.ExitingViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Event tracking the state of the object as it moves into and out of the viewport | ||
/// </summary> | ||
/// <param name="d">DependencyObject</param> | ||
/// <param name="e">EventArgs</param> | ||
private static void OnIsInViewportChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
var obj = (ViewportBehavior)d; | ||
var value = (bool)e.NewValue; | ||
|
||
if (value) | ||
{ | ||
obj.EnteringViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty); | ||
} | ||
else | ||
{ | ||
obj.ExitedViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty); | ||
} | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
UITests/UITests.Tests.Shared/Controls/ConstrainedBoxTest.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,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.UI.Xaml.Tests.MUXControls.InteractionTests.Common; | ||
using Microsoft.UI.Xaml.Tests.MUXControls.InteractionTests.Infra; | ||
using Microsoft.Windows.Apps.Test.Automation; | ||
using Microsoft.Windows.Apps.Test.Foundation; | ||
using Microsoft.Windows.Apps.Test.Foundation.Controls; | ||
|
||
#if USING_TAEF | ||
using WEX.Logging.Interop; | ||
using WEX.TestExecution; | ||
using WEX.TestExecution.Markup; | ||
#else | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
#endif | ||
|
||
namespace UITests.Tests | ||
{ | ||
[TestClass] | ||
public class ConstrainedBoxTest : UITestBase | ||
{ | ||
[ClassInitialize] | ||
[TestProperty("RunAs", "User")] | ||
[TestProperty("Classification", "ScenarioTestSuite")] | ||
[TestProperty("Platform", "Any")] | ||
public static void ClassInitialize(TestContext testContext) | ||
{ | ||
TestEnvironment.Initialize(testContext, UITestsAppSampleApp); | ||
} | ||
|
||
[TestMethod] | ||
[TestPage("ConstrainedBoxTestPage")] | ||
public void Test_AspectRatioBoundToInteger_Placeholder() | ||
{ | ||
// The test is if the AspectRatio can be bound to integer | ||
// This test method acts as a placeholder, to spawn the XAML test page | ||
// and test the binding to an integer | ||
} | ||
} | ||
} |
Oops, something went wrong.