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 ;
1
6
using System ;
2
7
using Windows . UI . Xaml ;
3
8
@@ -21,7 +26,7 @@ public partial class ViewportBehavior
21
26
/// The IsAlwaysOn value of the associated element
22
27
/// </summary>
23
28
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 ) ) ) ;
25
30
26
31
/// <summary>
27
32
/// 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
60
65
var obj = ( ViewportBehavior ) d ;
61
66
var value = ( bool ) e . NewValue ;
62
67
63
- if ( obj . IsAlwaysOn )
68
+ if ( value )
64
69
{
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 )
70
73
{
71
- obj . ExitingViewport ? . Invoke ( obj . AssociatedObject , EventArgs . Empty ) ;
74
+ Interaction . GetBehaviors ( obj . AssociatedObject ) . Remove ( obj ) ;
72
75
}
73
76
}
77
+ else
78
+ {
79
+ obj . ExitingViewport ? . Invoke ( obj . AssociatedObject , EventArgs . Empty ) ;
80
+ }
74
81
}
75
82
76
83
/// <summary>
@@ -83,16 +90,13 @@ private static void OnIsInViewportChanged(DependencyObject d, DependencyProperty
83
90
var obj = ( ViewportBehavior ) d ;
84
91
var value = ( bool ) e . NewValue ;
85
92
86
- if ( obj . IsAlwaysOn )
93
+ if ( value )
87
94
{
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 ) ;
96
100
}
97
101
}
98
102
}
0 commit comments