Bring back original impl, set IsAlwaysOn in Sample page to true
This commit is contained in:
Родитель
722dbb03c9
Коммит
0ce0cf3a2d
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -21,7 +26,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Behaviors
|
|||
/// 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.
|
||||
|
@ -60,17 +65,19 @@ namespace Microsoft.Toolkit.Uwp.UI.Behaviors
|
|||
var obj = (ViewportBehavior)d;
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.ExitingViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
|
||||
Interaction.GetBehaviors(obj.AssociatedObject).Remove(obj);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.ExitingViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -83,16 +90,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Behaviors
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче