Skip to content

Commit 65955ac

Browse files
authored
Feature: Migrate loading indicators to NETworkManager (#2963)
* Feature: Migrate loading indicators to NETworkManager * Feature: #2963
1 parent 4d26745 commit 65955ac

11 files changed

+327
-36
lines changed

Source/NETworkManager/App.xaml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,8 @@
1717
Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.FlatButton.xaml" />
1818
<ResourceDictionary
1919
Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.FlatSlider.xaml" />
20-
2120
<!-- Dragablz -->
2221
<ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/MahApps.xaml" />
23-
<!-- LoadingIndicators.WPF -->
24-
<ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles.xaml" />
25-
<ResourceDictionary
26-
Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingWave.xaml" />
27-
<ResourceDictionary
28-
Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingThreeDots.xaml" />
29-
<ResourceDictionary
30-
Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingFlipPlane.xaml" />
31-
<ResourceDictionary
32-
Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingPulse.xaml" />
33-
<ResourceDictionary
34-
Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingDoubleBounce.xaml" />
3522
<!-- Context menu (import berfore styles)-->
3623
<ResourceDictionary Source="/Resources/ContextMenu/ContextMenu.xaml" />
3724
<!-- Control templates (import before styles) -->
@@ -44,6 +31,8 @@
4431
<ResourceDictionary Source="/Resources/Styles/DropDownButtonStyles.xaml" />
4532
<ResourceDictionary Source="/Resources/Styles/GridSplitterStyles.xaml" />
4633
<ResourceDictionary Source="/Resources/Styles/GroupBoxStyles.xaml" />
34+
<ResourceDictionary Source="/Resources/Styles/LoadingIndicatorArcsStyle.xaml" />
35+
<ResourceDictionary Source="/Resources/Styles/LoadingIndicatorPulseStyle.xaml" />
4736
<ResourceDictionary Source="/Resources/Styles/MenuItemStyles.xaml" />
4837
<ResourceDictionary Source="/Resources/Styles/MetroDialogStyles.xaml" />
4938
<ResourceDictionary Source="/Resources/Styles/NumericUpDownStyles.xaml" />
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
4+
namespace NETworkManager;
5+
6+
/// <summary>
7+
/// A control featuring a range of loading indicating animations.
8+
/// Source: https://github.com/zeluisping/LoadingIndicators.WPF
9+
/// </summary>
10+
[TemplatePart(Name = "Border", Type = typeof(Border))]
11+
public class LoadingIndicator : Control
12+
{
13+
/// <summary>
14+
/// Identifies the <see cref="NETworkManager.LoadingIndicator.SpeedRatio"/> dependency property.
15+
/// </summary>
16+
public static readonly DependencyProperty SpeedRatioProperty =
17+
DependencyProperty.Register(nameof(SpeedRatio), typeof(double), typeof(LoadingIndicator), new PropertyMetadata(1d, (o, e) =>
18+
{
19+
LoadingIndicator li = (LoadingIndicator)o;
20+
21+
if (li.PART_Border == null || li.IsActive == false)
22+
{
23+
return;
24+
}
25+
26+
foreach (VisualStateGroup group in VisualStateManager.GetVisualStateGroups(li.PART_Border))
27+
{
28+
if (group.Name == "ActiveStates")
29+
{
30+
foreach (VisualState state in group.States)
31+
{
32+
if (state.Name == "Active")
33+
{
34+
state.Storyboard.SetSpeedRatio(li.PART_Border, (double)e.NewValue);
35+
}
36+
}
37+
}
38+
}
39+
}));
40+
41+
/// <summary>
42+
/// Identifies the <see cref="NETworkManager.LoadingIndicator.IsActive"/> dependency property.
43+
/// </summary>
44+
public static readonly DependencyProperty IsActiveProperty =
45+
DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(LoadingIndicator), new PropertyMetadata(true, (o, e) =>
46+
{
47+
LoadingIndicator li = (LoadingIndicator)o;
48+
49+
if (li.PART_Border == null)
50+
{
51+
return;
52+
}
53+
54+
if ((bool)e.NewValue == false)
55+
{
56+
VisualStateManager.GoToElementState(li.PART_Border, "Inactive", false);
57+
li.PART_Border.Visibility = Visibility.Collapsed;
58+
}
59+
else
60+
{
61+
VisualStateManager.GoToElementState(li.PART_Border, "Active", false);
62+
li.PART_Border.Visibility = Visibility.Visible;
63+
64+
foreach (VisualStateGroup group in VisualStateManager.GetVisualStateGroups(li.PART_Border))
65+
{
66+
if (group.Name == "ActiveStates")
67+
{
68+
foreach (VisualState state in group.States)
69+
{
70+
if (state.Name == "Active")
71+
{
72+
state.Storyboard.SetSpeedRatio(li.PART_Border, li.SpeedRatio);
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}));
79+
80+
// Variables
81+
protected Border PART_Border;
82+
83+
/// <summary>
84+
/// Get/set the speed ratio of the animation.
85+
/// </summary>
86+
public double SpeedRatio
87+
{
88+
get { return (double)GetValue(SpeedRatioProperty); }
89+
set { SetValue(SpeedRatioProperty, value); }
90+
}
91+
92+
/// <summary>
93+
/// Get/set whether the loading indicator is active.
94+
/// </summary>
95+
public bool IsActive
96+
{
97+
get { return (bool)GetValue(IsActiveProperty); }
98+
set { SetValue(IsActiveProperty, value); }
99+
}
100+
101+
/// <summary>
102+
/// When overridden in a derived class, is invoked whenever application code
103+
/// or internal processes call System.Windows.FrameworkElement.ApplyTemplate().
104+
/// </summary>
105+
public override void OnApplyTemplate()
106+
{
107+
base.OnApplyTemplate();
108+
109+
PART_Border = (Border)GetTemplateChild("PART_Border");
110+
111+
if (PART_Border != null)
112+
{
113+
VisualStateManager.GoToElementState(PART_Border, (this.IsActive ? "Active" : "Inactive"), false);
114+
foreach (VisualStateGroup group in VisualStateManager.GetVisualStateGroups(PART_Border))
115+
{
116+
if (group.Name == "ActiveStates")
117+
{
118+
foreach (VisualState state in group.States)
119+
{
120+
if (state.Name == "Active")
121+
{
122+
state.Storyboard.SetSpeedRatio(PART_Border, this.SpeedRatio);
123+
}
124+
}
125+
}
126+
}
127+
128+
PART_Border.Visibility = (IsActive ? Visibility.Visible : Visibility.Collapsed);
129+
}
130+
}
131+
132+
/// <summary>
133+
/// Initializes a new instance of the <see cref="NETworkManager.LoadingIndicator"/> class.
134+
/// </summary>
135+
public LoadingIndicator()
136+
{
137+
138+
}
139+
}

Source/NETworkManager/NETworkManager.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
<PackageReference Include="IPNetwork2" Version="3.0.667" />
6767
<PackageReference Include="Lextm.SharpSnmpLib" Version="12.5.5" />
6868
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
69-
<PackageReference Include="LoadingIndicators.WPF" Version="0.0.1" />
7069
<PackageReference Include="log4net" Version="3.0.3" />
7170
<PackageReference Include="MahApps.Metro" Version="2.4.10" />
7271
<PackageReference Include="MahApps.Metro.IconPacks.FontAwesome" Version="5.1.0" />
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:networkManager="clr-namespace:NETworkManager">
4+
<!--
5+
Source: https://github.com/BornToBeRoot/NETworkManager/issues/2949
6+
-->
7+
<Style x:Key="LoadingIndicatorArcsStyleKey" TargetType="{x:Type networkManager:LoadingIndicator}">
8+
<Setter Property="Foreground" Value="{DynamicResource ResourceKey=MahApps.Brushes.Accent}"/>
9+
<Setter Property="VerticalAlignment" Value="Center"/>
10+
<Setter Property="HorizontalAlignment" Value="Center"/>
11+
<Setter Property="Width" Value="40"/>
12+
<Setter Property="Height" Value="40"/>
13+
<Setter Property="Template">
14+
<Setter.Value>
15+
<ControlTemplate TargetType="{x:Type networkManager:LoadingIndicator}">
16+
<Border x:Name="PART_Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
17+
<VisualStateManager.VisualStateGroups>
18+
<VisualStateGroup x:Name="SizeStates">
19+
<VisualState x:Name="Large" />
20+
<VisualState x:Name="Small" />
21+
</VisualStateGroup>
22+
<VisualStateGroup x:Name="ActiveStates">
23+
<VisualState x:Name="Inactive"/>
24+
<VisualState x:Name="Active">
25+
<Storyboard SpeedRatio="{TemplateBinding SpeedRatio}">
26+
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetName="PART_Canvas0" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)">
27+
<LinearDoubleKeyFrame KeyTime="0:0:0.000" Value="0"/>
28+
<LinearDoubleKeyFrame KeyTime="0:0:3.000" Value="360"/>
29+
</DoubleAnimationUsingKeyFrames>
30+
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetName="PART_Canvas1" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)">
31+
<LinearDoubleKeyFrame KeyTime="0:0:0.000" Value="0"/>
32+
<LinearDoubleKeyFrame KeyTime="0:0:2.000" Value="-360"/>
33+
</DoubleAnimationUsingKeyFrames>
34+
</Storyboard>
35+
</VisualState>
36+
</VisualStateGroup>
37+
</VisualStateManager.VisualStateGroups>
38+
39+
<Border.Resources>
40+
<Style TargetType="{x:Type Canvas}">
41+
<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
42+
<Setter Property="RenderTransform">
43+
<Setter.Value>
44+
<RotateTransform/>
45+
</Setter.Value>
46+
</Setter>
47+
</Style>
48+
</Border.Resources>
49+
50+
<Grid Background="Transparent">
51+
<Grid.RenderTransform>
52+
<TransformGroup>
53+
<ScaleTransform ScaleX="0.5" ScaleY="0.5"/>
54+
<TranslateTransform X="10" Y="10"/>
55+
</TransformGroup>
56+
</Grid.RenderTransform>
57+
<Canvas x:Name="PART_Canvas0" Opacity="1.0">
58+
<Path Stroke="{TemplateBinding Foreground}" StrokeThickness="10">
59+
<Path.Data>
60+
<PathGeometry>
61+
<PathGeometry.Transform>
62+
<TranslateTransform X="20" Y="-20"/>
63+
</PathGeometry.Transform>
64+
<PathGeometry.Figures>
65+
<PathFigureCollection>
66+
<PathFigure StartPoint="0,0">
67+
<PathFigure.Segments>
68+
<PathSegmentCollection>
69+
<ArcSegment Size="40,40" IsLargeArc="True" SweepDirection="CounterClockwise" Point="40,40" />
70+
</PathSegmentCollection>
71+
</PathFigure.Segments>
72+
</PathFigure>
73+
</PathFigureCollection>
74+
</PathGeometry.Figures>
75+
</PathGeometry>
76+
</Path.Data>
77+
</Path>
78+
</Canvas>
79+
80+
<Canvas x:Name="PART_Canvas1" Opacity="0.3">
81+
<Path Stroke="{TemplateBinding Foreground}" StrokeThickness="10">
82+
<Path.Data>
83+
<PathGeometry>
84+
<PathGeometry.Transform>
85+
<TranslateTransform X="-7" Y="7"/>
86+
</PathGeometry.Transform>
87+
<PathGeometry.Figures>
88+
<PathFigureCollection>
89+
<PathFigure StartPoint="0,0">
90+
<PathFigure.Segments>
91+
<PathSegmentCollection>
92+
<ArcSegment Size="30,30" IsLargeArc="True" SweepDirection="Clockwise" Point="40,40" />
93+
</PathSegmentCollection>
94+
</PathFigure.Segments>
95+
</PathFigure>
96+
</PathFigureCollection>
97+
</PathGeometry.Figures>
98+
</PathGeometry>
99+
</Path.Data>
100+
</Path>
101+
</Canvas>
102+
</Grid>
103+
</Border>
104+
</ControlTemplate>
105+
</Setter.Value>
106+
</Setter>
107+
</Style>
108+
109+
<Style x:Key="LoadingIndicatorArcsStyle" TargetType="{x:Type networkManager:LoadingIndicator}" BasedOn="{StaticResource LoadingIndicatorArcsStyleKey}"/>
110+
</ResourceDictionary>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:networkManager="clr-namespace:NETworkManager">
4+
<!--
5+
Source: https://github.com/BornToBeRoot/NETworkManager/issues/2949
6+
-->
7+
8+
<Style x:Key="LoadingIndicatorPulseStyleKey" TargetType="{x:Type networkManager:LoadingIndicator}">
9+
<Setter Property="Foreground" Value="{DynamicResource ResourceKey=MahApps.Brushes.Accent}"/>
10+
<Setter Property="VerticalAlignment" Value="Center"/>
11+
<Setter Property="HorizontalAlignment" Value="Center"/>
12+
<Setter Property="Width" Value="40"/>
13+
<Setter Property="Height" Value="40"/>
14+
<Setter Property="Template">
15+
<Setter.Value>
16+
<ControlTemplate TargetType="{x:Type networkManager:LoadingIndicator}">
17+
<Border x:Name="PART_Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
18+
<VisualStateManager.VisualStateGroups>
19+
<VisualStateGroup x:Name="SizeStates">
20+
<VisualState x:Name="Large" />
21+
<VisualState x:Name="Small" />
22+
</VisualStateGroup>
23+
<VisualStateGroup x:Name="ActiveStates">
24+
<VisualState x:Name="Inactive"/>
25+
<VisualState x:Name="Active">
26+
<Storyboard SpeedRatio="{TemplateBinding SpeedRatio}" RepeatBehavior="Forever" Duration="0:0:1.500">
27+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_Ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
28+
<LinearDoubleKeyFrame KeyTime="0:0:0.000" Value="0"/>
29+
<LinearDoubleKeyFrame KeyTime="0:0:1.500" Value="1"/>
30+
</DoubleAnimationUsingKeyFrames>
31+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_Ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)">
32+
<LinearDoubleKeyFrame KeyTime="0:0:0.000" Value="0"/>
33+
<LinearDoubleKeyFrame KeyTime="0:0:1.500" Value="1"/>
34+
</DoubleAnimationUsingKeyFrames>
35+
<DoubleAnimation From="1" To="0" Duration="0:0:1.500" Storyboard.TargetName="PART_Ellipse" Storyboard.TargetProperty="(UIElement.Opacity)"/>
36+
</Storyboard>
37+
</VisualState>
38+
</VisualStateGroup>
39+
</VisualStateManager.VisualStateGroups>
40+
41+
<Grid Background="Transparent">
42+
<Ellipse x:Name="PART_Ellipse" RenderTransformOrigin="0.5,0.5" Fill="{TemplateBinding Foreground}">
43+
<Ellipse.RenderTransform>
44+
<ScaleTransform/>
45+
</Ellipse.RenderTransform>
46+
</Ellipse>
47+
</Grid>
48+
</Border>
49+
</ControlTemplate>
50+
</Setter.Value>
51+
</Setter>
52+
</Style>
53+
54+
<Style x:Key="LoadingIndicatorPulseStyle" TargetType="{x:Type networkManager:LoadingIndicator}" BasedOn="{StaticResource LoadingIndicatorPulseStyleKey}"/>
55+
</ResourceDictionary>

0 commit comments

Comments
 (0)