-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Property panel for ViewportBehavior #4320
Merged
michael-hawker
merged 5 commits into
CommunityToolkit:main
from
XAML-Knight:dev/ViewportLogging
Oct 15, 2021
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d766b9e
Initial commit
XAML-Knight 7ef1918
Moved code into *.Properties.cs file, wired up IsAlwaysOn flag
XAML-Knight 722dbb0
update params comment
XAML-Knight 0ce0cf3
Bring back original impl, set IsAlwaysOn in Sample page to true
XAML-Knight 74021fb
Address CI build errors
XAML-Knight File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
99 changes: 99 additions & 0 deletions
99
Microsoft.Toolkit.Uwp.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,99 @@ | ||
using System; | ||
michael-hawker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
using Windows.UI.Xaml; | ||
|
||
namespace Microsoft.Toolkit.Uwp.UI.Behaviors | ||
{ | ||
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 = | ||
michael-hawker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
DependencyProperty.Register(nameof(IsAlwaysOn), typeof(bool), typeof(ViewportBehavior), new PropertyMetadata(true)); | ||
|
||
/// <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 (obj.IsAlwaysOn) | ||
{ | ||
if (value) | ||
{ | ||
obj.EnteredViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty); | ||
} | ||
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 (obj.IsAlwaysOn) | ||
{ | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rather than a toggle we just want this to be on by default (for the sample)?