Skip to content

Commit

Permalink
Bring back original impl, set IsAlwaysOn in Sample page to true
Browse files Browse the repository at this point in the history
  • Loading branch information
XAML-Knight committed Oct 14, 2021
1 parent 722dbb0 commit 0ce0cf3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Height="200"
Background="Gray">
<interactivity:Interaction.Behaviors>
<behaviors:ViewportBehavior x:Name="ViewportBehavior" IsAlwaysOn="@[IsAlwaysOn:Bool:True]" />
<behaviors:ViewportBehavior x:Name="ViewportBehavior" IsAlwaysOn="True" />
</interactivity:Interaction.Behaviors>
<Image x:Name="EffectElement"
Width="100"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// 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.Xaml.Interactivity;
using System;
using Windows.UI.Xaml;

Expand All @@ -21,7 +26,7 @@ public partial class ViewportBehavior
/// The IsAlwaysOn value of the associated element
/// </summary>
public static readonly DependencyProperty IsAlwaysOnProperty =
DependencyProperty.Register(nameof(IsAlwaysOn), typeof(bool), typeof(ViewportBehavior), new PropertyMetadata(true));
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.
Expand Down Expand Up @@ -60,17 +65,19 @@ private static void OnIsFullyInViewportChanged(DependencyObject d, DependencyPro
var obj = (ViewportBehavior)d;
var value = (bool)e.NewValue;

if (obj.IsAlwaysOn)
if (value)
{
if (value)
{
obj.EnteredViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
}
else
obj.EnteredViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);

if (!obj.IsAlwaysOn)
{
obj.ExitingViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
Interaction.GetBehaviors(obj.AssociatedObject).Remove(obj);
}
}
else
{
obj.ExitingViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
}
}

/// <summary>
Expand All @@ -83,16 +90,13 @@ private static void OnIsInViewportChanged(DependencyObject d, DependencyProperty
var obj = (ViewportBehavior)d;
var value = (bool)e.NewValue;

if (obj.IsAlwaysOn)
if (value)
{
if (value)
{
obj.EnteringViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
}
else
{
obj.ExitedViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
}
obj.EnteringViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
}
else
{
obj.ExitedViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
}
}
}
Expand Down

0 comments on commit 0ce0cf3

Please sign in to comment.