Skip to content

Commit 1614cf9

Browse files
Flyout animation toggle (#511)
* widget animation toggle * translation added * Flyout animation toggle - done * minor changes * typo in ru translation
1 parent 59a0516 commit 1614cf9

37 files changed

+3148
-60
lines changed

ModernFlyouts.Core/UI/FlyoutWindow/FlyoutWindow.Animations.cs

+29-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Windows.Media;
44
using System.Windows.Media.Animation;
55
using System.Windows.Threading;
6+
using MessageBox = System.Windows.Forms.MessageBox;
67

78
namespace ModernFlyouts.Core.UI
89
{
@@ -18,7 +19,21 @@ private void OpenFlyout()
1819
RoutedEventArgs args = new(OpenedEvent);
1920
RaiseEvent(args);
2021

21-
PlayOpenAnimation();
22+
23+
if (FlyoutAnimationEnabled)
24+
{
25+
c_translation = 40;
26+
PlayOpenAnimation();
27+
}
28+
else
29+
{
30+
c_translation = 0;
31+
RenderTransform = new TranslateTransform();
32+
BeginAnimation(VisibilityProperty, null);
33+
BeginAnimation(OpacityProperty, null);
34+
Visibility = Visibility.Visible;
35+
Opacity = 1.0;
36+
}
2237

2338
timer?.Start();
2439
}
@@ -28,7 +43,15 @@ private void CloseFlyout()
2843
RoutedEventArgs args = new(ClosingEvent);
2944
RaiseEvent(args);
3045

31-
PlayCloseAnimation();
46+
if (FlyoutAnimationEnabled)
47+
{
48+
PlayCloseAnimation();
49+
}
50+
else
51+
{
52+
Opacity = 0.0;
53+
Visibility = Visibility.Hidden;
54+
}
3255
}
3356

3457
#region Close Timer
@@ -105,7 +128,7 @@ public void UpdateCloseTimerInterval(double timeout)
105128
private DoubleKeyFrame fromHorizontalOffsetKeyFrameClosing;
106129
private DoubleKeyFrame fromVerticalOffsetKeyFrameClosing;
107130

108-
private const double c_translation = 40;
131+
private double c_translation = 40;
109132
private static readonly TimeSpan translateDuration = TimeSpan.FromMilliseconds(367);
110133

111134
private static readonly PropertyPath opacityPath = new(OpacityProperty);
@@ -115,6 +138,7 @@ public void UpdateCloseTimerInterval(double timeout)
115138
private static readonly KeySpline decelerateKeySplineOpening = new(0.1, 0.9, 0.2, 1);
116139
private static readonly KeySpline decelerateKeySplineClosing = new(1, 0.2, 0.9, 0.1);
117140

141+
118142
private void PrepareAnimations()
119143
{
120144
EnsureClosingStoryboard();
@@ -141,9 +165,11 @@ private void EnsureOpeningStoryboard()
141165
{
142166
new DiscreteObjectKeyFrame(Visibility.Visible, TimeSpan.Zero)
143167
}
168+
144169
};
145170
Storyboard.SetTarget(visibilityAnim, this);
146171
Storyboard.SetTargetProperty(visibilityAnim, visibilityPath);
172+
147173

148174
DoubleAnimationUsingKeyFrames opacityAnim = new()
149175
{

ModernFlyouts.Core/UI/FlyoutWindow/FlyoutWindow.Properties.cs

+17
Original file line numberDiff line numberDiff line change
@@ -345,5 +345,22 @@ private static void OnIsOpenPropertyChanged(DependencyObject d, DependencyProper
345345
}
346346

347347
#endregion
348+
349+
#region FlyoutAnimationEnabled
350+
351+
public static readonly DependencyProperty FlyoutAnimationEnabledProperty =
352+
DependencyProperty.Register(
353+
nameof(FlyoutAnimationEnabled),
354+
typeof(bool),
355+
typeof(FlyoutWindow),
356+
new PropertyMetadata(false));
357+
358+
public bool FlyoutAnimationEnabled
359+
{
360+
get => (bool)GetValue(FlyoutAnimationEnabledProperty);
361+
set => SetValue(FlyoutAnimationEnabledProperty, value);
362+
}
363+
364+
#endregion
348365
}
349366
}

ModernFlyouts/FlyoutHandler.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private void CreateOnScreenFlyoutWindow()
215215
ZBandID = zbid,
216216
FlyoutWindowType = FlyoutWindowType.OnScreen,
217217
Offset = UIManager.FlyoutShadowMargin,
218-
IsTimeoutEnabled = true
218+
IsTimeoutEnabled = true,
219219
};
220220

221221
flyoutWindow.DragMoved += (s, e) =>
@@ -278,6 +278,13 @@ private void CreateOnScreenFlyoutWindow()
278278
Path = new PropertyPath(nameof(UIManager.OnScreenFlyoutWindowExpandDirection)),
279279
Mode = BindingMode.OneWay
280280
});
281+
282+
BindingOperations.SetBinding(flyoutWindow, FlyoutWindow.FlyoutAnimationEnabledProperty, new Binding()
283+
{
284+
Source = UIManager,
285+
Path = new PropertyPath(nameof(UIManager.FlyoutAnimationEnabled)),
286+
Mode = BindingMode.OneWay
287+
});
281288
}
282289

283290
private void OnNativeFlyoutShown()

ModernFlyouts/Helpers/AppDataHelper.cs

+6
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ public static bool UseColoredTrayIcon
289289
set => SetValue(value);
290290
}
291291

292+
public static bool FlyoutAnimationEnabled
293+
{
294+
get => GetValue(DefaultValuesStore.FlyoutAnimationEnabled);
295+
set => SetValue(value);
296+
}
297+
292298
public static bool AlignGSMTCThumbnailToRight
293299
{
294300
get => GetValue(DefaultValuesStore.AlignGSMTCThumbnailToRight);

ModernFlyouts/Helpers/DefaultValuesStore.cs

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ internal class DefaultValuesStore
8282

8383
public const bool UseColoredTrayIcon = true;
8484

85+
public const bool FlyoutAnimationEnabled = true;
86+
8587
public const bool AlignGSMTCThumbnailToRight = true;
8688

8789
public const bool UseGSMTCThumbnailAsBackground = true;

ModernFlyouts/Navigation/PersonalizationPage.xaml

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
OffContent="{x:Static resx:Strings.Settings_Off}"
4949
Visibility="{Binding UIManager.TrayIconEnabled,
5050
Converter={StaticResource BooleanToVisibilityConverter}}" />
51+
<ui:ToggleSwitch Header="{x:Static resx:Strings.Settings_FlyoutAnimationEnabled}"
52+
IsOn="{Binding UIManager.FlyoutAnimationEnabled}"
53+
OnContent="{x:Static resx:Strings.Settings_On}"
54+
OffContent="{x:Static resx:Strings.Settings_Off}" />
5155
</ui:SimpleStackPanel>
5256
</GroupBox>
5357

ModernFlyouts/Properties/Strings.Designer.cs

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ModernFlyouts/Properties/Strings.af.resx

+110-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,121 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
3108
<resheader name="resmimetype">
4109
<value>text/microsoft-resx</value>
5110
</resheader>
6111
<resheader name="version">
7112
<value>2.0</value>
8113
</resheader>
9114
<resheader name="reader">
10-
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
11116
</resheader>
12117
<resheader name="writer">
13-
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
14119
</resheader>
15120
<data name="About" xml:space="preserve">
16121
<value>Inligting oor</value>
@@ -314,4 +419,7 @@
314419
<data name="Settings.RestartRequired" xml:space="preserve">
315420
<value>Herbegin vereis om sekere veranderinge toe te pas</value>
316421
</data>
422+
<data name="Settings.FlyoutAnimationEnabled" xml:space="preserve">
423+
<value>Vervaag animasie</value>
424+
</data>
317425
</root>

0 commit comments

Comments
 (0)