Skip to content

Commit 0ce0cf3

Browse files
committed
Bring back original impl, set IsAlwaysOn in Sample page to true
1 parent 722dbb0 commit 0ce0cf3

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ViewportBehavior/ViewportBehaviorXaml.bind

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Height="200"
1515
Background="Gray">
1616
<interactivity:Interaction.Behaviors>
17-
<behaviors:ViewportBehavior x:Name="ViewportBehavior" IsAlwaysOn="@[IsAlwaysOn:Bool:True]" />
17+
<behaviors:ViewportBehavior x:Name="ViewportBehavior" IsAlwaysOn="True" />
1818
</interactivity:Interaction.Behaviors>
1919
<Image x:Name="EffectElement"
2020
Width="100"

Microsoft.Toolkit.Uwp.UI.Behaviors/Viewport/ViewportBehavior.Properties.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.Xaml.Interactivity;
16
using System;
27
using Windows.UI.Xaml;
38

@@ -21,7 +26,7 @@ public partial class ViewportBehavior
2126
/// The IsAlwaysOn value of the associated element
2227
/// </summary>
2328
public static readonly DependencyProperty IsAlwaysOnProperty =
24-
DependencyProperty.Register(nameof(IsAlwaysOn), typeof(bool), typeof(ViewportBehavior), new PropertyMetadata(true));
29+
DependencyProperty.Register(nameof(IsAlwaysOn), typeof(bool), typeof(ViewportBehavior), new PropertyMetadata(default(bool)));
2530

2631
/// <summary>
2732
/// 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 @@ private static void OnIsFullyInViewportChanged(DependencyObject d, DependencyPro
6065
var obj = (ViewportBehavior)d;
6166
var value = (bool)e.NewValue;
6267

63-
if (obj.IsAlwaysOn)
68+
if (value)
6469
{
65-
if (value)
66-
{
67-
obj.EnteredViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
68-
}
69-
else
70+
obj.EnteredViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
71+
72+
if (!obj.IsAlwaysOn)
7073
{
71-
obj.ExitingViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
74+
Interaction.GetBehaviors(obj.AssociatedObject).Remove(obj);
7275
}
7376
}
77+
else
78+
{
79+
obj.ExitingViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
80+
}
7481
}
7582

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

86-
if (obj.IsAlwaysOn)
93+
if (value)
8794
{
88-
if (value)
89-
{
90-
obj.EnteringViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
91-
}
92-
else
93-
{
94-
obj.ExitedViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
95-
}
95+
obj.EnteringViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
96+
}
97+
else
98+
{
99+
obj.ExitedViewport?.Invoke(obj.AssociatedObject, EventArgs.Empty);
96100
}
97101
}
98102
}

0 commit comments

Comments
 (0)