Bring back original impl, set IsAlwaysOn in Sample page to true

This commit is contained in:
Darren Batchelor 2021-10-14 14:01:31 -07:00
Родитель 722dbb03c9
Коммит 0ce0cf3a2d
2 изменённых файлов: 22 добавлений и 18 удалений

Просмотреть файл

@ -14,7 +14,7 @@
Height="200" Height="200"
Background="Gray"> Background="Gray">
<interactivity:Interaction.Behaviors> <interactivity:Interaction.Behaviors>
<behaviors:ViewportBehavior x:Name="ViewportBehavior" IsAlwaysOn="@[IsAlwaysOn:Bool:True]" /> <behaviors:ViewportBehavior x:Name="ViewportBehavior" IsAlwaysOn="True" />
</interactivity:Interaction.Behaviors> </interactivity:Interaction.Behaviors>
<Image x:Name="EffectElement" <Image x:Name="EffectElement"
Width="100" Width="100"

Просмотреть файл

@ -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 System;
using Windows.UI.Xaml; using Windows.UI.Xaml;
@ -21,7 +26,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Behaviors
/// The IsAlwaysOn value of the associated element /// The IsAlwaysOn value of the associated element
/// </summary> /// </summary>
public static readonly DependencyProperty IsAlwaysOnProperty = 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> /// <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. /// 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.
@ -60,17 +65,19 @@ namespace Microsoft.Toolkit.Uwp.UI.Behaviors
var obj = (ViewportBehavior)d; var obj = (ViewportBehavior)d;
var value = (bool)e.NewValue; var value = (bool)e.NewValue;
if (obj.IsAlwaysOn) if (value)
{ {
if (value) obj.EnteredViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
if (!obj.IsAlwaysOn)
{ {
obj.EnteredViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty); Interaction.GetBehaviors(obj.AssociatedObject).Remove(obj);
}
else
{
obj.ExitingViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
} }
} }
else
{
obj.ExitingViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
}
} }
/// <summary> /// <summary>
@ -83,16 +90,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Behaviors
var obj = (ViewportBehavior)d; var obj = (ViewportBehavior)d;
var value = (bool)e.NewValue; var value = (bool)e.NewValue;
if (obj.IsAlwaysOn) if (value)
{ {
if (value) obj.EnteringViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
{ }
obj.EnteringViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty); else
} {
else obj.ExitedViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
{
obj.ExitedViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
}
} }
} }
} }