8
8
9
9
namespace SIUI . Behaviors
10
10
{
11
+ /// <summary>
12
+ /// Enables text reading effects ("karaoke").
13
+ /// </summary>
11
14
public static class QuestionReading
12
15
{
13
- public static bool GetIsAttached ( DependencyObject obj )
14
- {
15
- return ( bool ) obj . GetValue ( IsAttachedProperty ) ;
16
- }
16
+ public static bool GetIsAttached ( DependencyObject obj ) => ( bool ) obj . GetValue ( IsAttachedProperty ) ;
17
17
18
- public static void SetIsAttached ( DependencyObject obj , bool value )
19
- {
20
- obj . SetValue ( IsAttachedProperty , value ) ;
21
- }
18
+ public static void SetIsAttached ( DependencyObject obj , bool value ) => obj . SetValue ( IsAttachedProperty , value ) ;
22
19
23
20
// Using a DependencyProperty as the backing store for IsAttached. This enables animation, styling, binding, etc...
24
21
public static readonly DependencyProperty IsAttachedProperty =
@@ -29,6 +26,11 @@ public static void OnIsAttachedChanged(DependencyObject d, DependencyPropertyCha
29
26
var textBlock = ( TextBlock ) d ;
30
27
var tableInfoViewModel = ( TableInfoViewModel ) textBlock . DataContext ;
31
28
29
+ if ( tableInfoViewModel . TextSpeed < double . Epsilon )
30
+ {
31
+ return ;
32
+ }
33
+
32
34
textBlock . Loaded += ( sender , e2 ) =>
33
35
{
34
36
textBlock . TextEffects [ 0 ] . BeginAnimation (
@@ -41,28 +43,32 @@ public static void OnIsAttachedChanged(DependencyObject d, DependencyPropertyCha
41
43
} ;
42
44
}
43
45
44
- public static bool GetIsAttachedPartial ( DependencyObject obj )
45
- {
46
- return ( bool ) obj . GetValue ( IsAttachedPartialProperty ) ;
47
- }
46
+ public static bool GetIsAttachedPartial ( DependencyObject obj ) => ( bool ) obj . GetValue ( IsAttachedPartialProperty ) ;
48
47
49
- public static void SetIsAttachedPartial ( DependencyObject obj , bool value )
50
- {
51
- obj . SetValue ( IsAttachedPartialProperty , value ) ;
52
- }
48
+ public static void SetIsAttachedPartial ( DependencyObject obj , bool value ) => obj . SetValue ( IsAttachedPartialProperty , value ) ;
53
49
54
50
// Using a DependencyProperty as the backing store for IsAttachedPartial. This enables animation, styling, binding, etc...
55
51
public static readonly DependencyProperty IsAttachedPartialProperty =
56
52
DependencyProperty . RegisterAttached ( "IsAttachedPartial" , typeof ( bool ) , typeof ( QuestionReading ) , new PropertyMetadata ( false , OnIsAttachedPartialChanged ) ) ;
57
53
58
54
// Пока сделано синглтоном
59
- public static int CurrentTarget ;
55
+ private static int CurrentTarget ;
60
56
61
57
public static void OnIsAttachedPartialChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
62
58
{
63
59
var textBlock = ( TextBlock ) d ;
64
60
var tableInfoViewModel = ( TableInfoViewModel ) textBlock . DataContext ;
65
61
62
+ if ( ! ( bool ) e . NewValue )
63
+ {
64
+ return ;
65
+ }
66
+
67
+ if ( tableInfoViewModel . TextSpeed < double . Epsilon )
68
+ {
69
+ return ;
70
+ }
71
+
66
72
void handler ( object sender , PropertyChangedEventArgs e2 )
67
73
{
68
74
if ( e2 . PropertyName == nameof ( TableInfoViewModel . TextLength ) )
@@ -71,11 +77,6 @@ void handler(object sender, PropertyChangedEventArgs e2)
71
77
}
72
78
}
73
79
74
- if ( ! ( bool ) e . NewValue )
75
- {
76
- return ;
77
- }
78
-
79
80
tableInfoViewModel . PropertyChanged += handler ;
80
81
81
82
textBlock . Loaded += ( sender , e2 ) =>
0 commit comments