4 namespace Tizen.Xamarin.Forms.Extension
7 /// Enumeration for the slide mode of a text.
9 public enum TextSlideMode
12 /// The text appears on the left of the view and slides to the right to show the overflow. When all of the text has been shown, the position is reset.
17 /// The entire text appears from the right of the screen and slides until it disappears to the left of the screen(reappearing on the right again).
22 /// The text appears on the left of the view and slides to the right to show the overflow. When all of the text has been shown, the animation reverses, moving the text to the left.
28 /// An effect that can make text sliding.
34 /// Text = "Test Slide Text",
39 public static class TextSlideEffect
42 /// BindableProperty. Implements the attached property that represents the style about how the text slides.
44 public static readonly BindableProperty ModeProperty = BindableProperty.CreateAttached("Mode", typeof(TextSlideMode), typeof(TextSlideEffect), TextSlideMode.Long);
47 /// BindableProperty. Implements the attached property that represents the slide mode.
49 public static readonly BindableProperty IsAlwaysOnProperty = BindableProperty.CreateAttached("IsAlwaysOn", typeof(bool), typeof(TextSlideEffect), false);
52 /// BindableProperty. Implements the attached property that represents the slide duration.
54 public static readonly BindableProperty DurationProperty = BindableProperty.CreateAttached("Duration", typeof(int), typeof(TextSlideEffect), 3000);
57 /// BindableProperty. Implements the attached property that represents the style when the text slides.
59 public static readonly BindableProperty IsTextSlidingProperty = BindableProperty.CreateAttached("IsTextSliding", typeof(bool), typeof(TextSlideEffect), false, propertyChanged: OnIsTextSlidingChanged);
62 /// Gets the TextSlideMode of the bindable element.
64 public static TextSlideMode GetMode(BindableObject view)
66 return (TextSlideMode)view.GetValue(ModeProperty);
70 /// Sets the TextSlideMode of the bindable element.
72 public static void SetMode(BindableObject view, TextSlideMode value)
74 view.SetValue(ModeProperty, value);
78 /// Gets the IsAlwaysOn of the bindable element.
80 public static bool GetIsAlwaysOn(BindableObject view)
82 return (bool)view.GetValue(IsAlwaysOnProperty);
86 /// Sets the IsAlwaysOn of the bindable element.
89 /// When the value is set to false, text will only slide when the length of the text is longer a View.
90 /// Otherwise, the text will always slide.
92 public static void SetIsAlwaysOn(BindableObject view, bool value)
94 view.SetValue(IsAlwaysOnProperty, value);
98 /// Gets the Duration of the bindable element.
100 public static int GetDuration(BindableObject view)
102 return (int)view.GetValue(DurationProperty);
106 /// Sets the Duration(in milliseconds) of the bindable element.
108 public static void SetDuration(BindableObject view, int value)
110 view.SetValue(DurationProperty, value);
114 /// Gets the sliding status of the bindable element.
116 public static bool GetIsTextSliding(BindableObject view)
118 return (bool)view.GetValue(IsTextSlidingProperty);
122 /// Sets the sliding status of the bindable element.
125 /// This method only works properly when the text is not wrapped.
126 /// For example, if the Label.LineBreakMode is set to any options other than NoWrap,
127 /// the Text will not be sliding.
129 /// <seealso cref="SetIsAlwaysOn(BindableObject, bool)"/>
130 public static void SetIsTextSliding(BindableObject view, bool value)
132 view.SetValue(IsTextSlidingProperty, value);
135 static void OnIsTextSlidingChanged(BindableObject bindable, object oldValue, object newValue)
137 var label = bindable as Label;
141 bool isEnable = (bool)newValue;
144 label.Effects.Add(new LabelSlideEffect());
148 var toRemove = label.Effects.FirstOrDefault(e => e is LabelSlideEffect);
149 if (toRemove != null)
150 label.Effects.Remove(toRemove);
154 class LabelSlideEffect : RoutingEffect
156 public LabelSlideEffect() : base("Tizen.LabelSlideEffect")