Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions Source/NETworkManager/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,8 @@
Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.FlatButton.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.FlatSlider.xaml" />

<!-- Dragablz -->
<ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/MahApps.xaml" />
<!-- LoadingIndicators.WPF -->
<ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles.xaml" />
<ResourceDictionary
Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingWave.xaml" />
<ResourceDictionary
Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingThreeDots.xaml" />
<ResourceDictionary
Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingFlipPlane.xaml" />
<ResourceDictionary
Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingPulse.xaml" />
<ResourceDictionary
Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingDoubleBounce.xaml" />
<!-- Context menu (import berfore styles)-->
<ResourceDictionary Source="/Resources/ContextMenu/ContextMenu.xaml" />
<!-- Control templates (import before styles) -->
Expand All @@ -44,6 +31,8 @@
<ResourceDictionary Source="/Resources/Styles/DropDownButtonStyles.xaml" />
<ResourceDictionary Source="/Resources/Styles/GridSplitterStyles.xaml" />
<ResourceDictionary Source="/Resources/Styles/GroupBoxStyles.xaml" />
<ResourceDictionary Source="/Resources/Styles/LoadingIndicatorArcsStyle.xaml" />
<ResourceDictionary Source="/Resources/Styles/LoadingIndicatorPulseStyle.xaml" />
<ResourceDictionary Source="/Resources/Styles/MenuItemStyles.xaml" />
<ResourceDictionary Source="/Resources/Styles/MetroDialogStyles.xaml" />
<ResourceDictionary Source="/Resources/Styles/NumericUpDownStyles.xaml" />
Expand Down
139 changes: 139 additions & 0 deletions Source/NETworkManager/LoadingIndicators.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using System.Windows;
using System.Windows.Controls;

namespace NETworkManager;

/// <summary>
/// A control featuring a range of loading indicating animations.
/// Source: https://github.com/zeluisping/LoadingIndicators.WPF
/// </summary>
[TemplatePart(Name = "Border", Type = typeof(Border))]
public class LoadingIndicator : Control
{
/// <summary>
/// Identifies the <see cref="NETworkManager.LoadingIndicator.SpeedRatio"/> dependency property.
/// </summary>
public static readonly DependencyProperty SpeedRatioProperty =
DependencyProperty.Register(nameof(SpeedRatio), typeof(double), typeof(LoadingIndicator), new PropertyMetadata(1d, (o, e) =>
{
LoadingIndicator li = (LoadingIndicator)o;

if (li.PART_Border == null || li.IsActive == false)
{
return;
}

foreach (VisualStateGroup group in VisualStateManager.GetVisualStateGroups(li.PART_Border))
{
if (group.Name == "ActiveStates")
{
foreach (VisualState state in group.States)
{
if (state.Name == "Active")
{
state.Storyboard.SetSpeedRatio(li.PART_Border, (double)e.NewValue);
}
}
}
}
}));

/// <summary>
/// Identifies the <see cref="NETworkManager.LoadingIndicator.IsActive"/> dependency property.
/// </summary>
public static readonly DependencyProperty IsActiveProperty =
DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(LoadingIndicator), new PropertyMetadata(true, (o, e) =>
{
LoadingIndicator li = (LoadingIndicator)o;

if (li.PART_Border == null)
{
return;
}

if ((bool)e.NewValue == false)
{
VisualStateManager.GoToElementState(li.PART_Border, "Inactive", false);
li.PART_Border.Visibility = Visibility.Collapsed;
}
else
{
VisualStateManager.GoToElementState(li.PART_Border, "Active", false);
li.PART_Border.Visibility = Visibility.Visible;

foreach (VisualStateGroup group in VisualStateManager.GetVisualStateGroups(li.PART_Border))
{
if (group.Name == "ActiveStates")
{
foreach (VisualState state in group.States)
{
if (state.Name == "Active")
{
state.Storyboard.SetSpeedRatio(li.PART_Border, li.SpeedRatio);
}
}
}
}
}
}));

// Variables
protected Border PART_Border;

/// <summary>
/// Get/set the speed ratio of the animation.
/// </summary>
public double SpeedRatio
{
get { return (double)GetValue(SpeedRatioProperty); }
set { SetValue(SpeedRatioProperty, value); }
}

/// <summary>
/// Get/set whether the loading indicator is active.
/// </summary>
public bool IsActive
{
get { return (bool)GetValue(IsActiveProperty); }
set { SetValue(IsActiveProperty, value); }
}

/// <summary>
/// When overridden in a derived class, is invoked whenever application code
/// or internal processes call System.Windows.FrameworkElement.ApplyTemplate().
/// </summary>
public override void OnApplyTemplate()
{
base.OnApplyTemplate();

PART_Border = (Border)GetTemplateChild("PART_Border");

if (PART_Border != null)
{
VisualStateManager.GoToElementState(PART_Border, (this.IsActive ? "Active" : "Inactive"), false);
foreach (VisualStateGroup group in VisualStateManager.GetVisualStateGroups(PART_Border))
{
if (group.Name == "ActiveStates")
{
foreach (VisualState state in group.States)
{
if (state.Name == "Active")
{
state.Storyboard.SetSpeedRatio(PART_Border, this.SpeedRatio);
}
}
}
}

PART_Border.Visibility = (IsActive ? Visibility.Visible : Visibility.Collapsed);
}
}

/// <summary>
/// Initializes a new instance of the <see cref="NETworkManager.LoadingIndicator"/> class.
/// </summary>
public LoadingIndicator()
{

}
}
1 change: 0 additions & 1 deletion Source/NETworkManager/NETworkManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
<PackageReference Include="IPNetwork2" Version="3.0.667" />
<PackageReference Include="Lextm.SharpSnmpLib" Version="12.5.5" />
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
<PackageReference Include="LoadingIndicators.WPF" Version="0.0.1" />
<PackageReference Include="log4net" Version="3.0.3" />
<PackageReference Include="MahApps.Metro" Version="2.4.10" />
<PackageReference Include="MahApps.Metro.IconPacks.FontAwesome" Version="5.1.0" />
Expand Down
110 changes: 110 additions & 0 deletions Source/NETworkManager/Resources/Styles/LoadingIndicatorArcsStyle.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:networkManager="clr-namespace:NETworkManager">
<!--
Source: https://github.com/BornToBeRoot/NETworkManager/issues/2949
-->
<Style x:Key="LoadingIndicatorArcsStyleKey" TargetType="{x:Type networkManager:LoadingIndicator}">
<Setter Property="Foreground" Value="{DynamicResource ResourceKey=MahApps.Brushes.Accent}"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Width" Value="40"/>
<Setter Property="Height" Value="40"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type networkManager:LoadingIndicator}">
<Border x:Name="PART_Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SizeStates">
<VisualState x:Name="Large" />
<VisualState x:Name="Small" />
</VisualStateGroup>
<VisualStateGroup x:Name="ActiveStates">
<VisualState x:Name="Inactive"/>
<VisualState x:Name="Active">
<Storyboard SpeedRatio="{TemplateBinding SpeedRatio}">
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetName="PART_Canvas0" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)">
<LinearDoubleKeyFrame KeyTime="0:0:0.000" Value="0"/>
<LinearDoubleKeyFrame KeyTime="0:0:3.000" Value="360"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetName="PART_Canvas1" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)">
<LinearDoubleKeyFrame KeyTime="0:0:0.000" Value="0"/>
<LinearDoubleKeyFrame KeyTime="0:0:2.000" Value="-360"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<Border.Resources>
<Style TargetType="{x:Type Canvas}">
<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
<Setter Property="RenderTransform">
<Setter.Value>
<RotateTransform/>
</Setter.Value>
</Setter>
</Style>
</Border.Resources>

<Grid Background="Transparent">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="0.5" ScaleY="0.5"/>
<TranslateTransform X="10" Y="10"/>
</TransformGroup>
</Grid.RenderTransform>
<Canvas x:Name="PART_Canvas0" Opacity="1.0">
<Path Stroke="{TemplateBinding Foreground}" StrokeThickness="10">
<Path.Data>
<PathGeometry>
<PathGeometry.Transform>
<TranslateTransform X="20" Y="-20"/>
</PathGeometry.Transform>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="0,0">
<PathFigure.Segments>
<PathSegmentCollection>
<ArcSegment Size="40,40" IsLargeArc="True" SweepDirection="CounterClockwise" Point="40,40" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>

<Canvas x:Name="PART_Canvas1" Opacity="0.3">
<Path Stroke="{TemplateBinding Foreground}" StrokeThickness="10">
<Path.Data>
<PathGeometry>
<PathGeometry.Transform>
<TranslateTransform X="-7" Y="7"/>
</PathGeometry.Transform>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="0,0">
<PathFigure.Segments>
<PathSegmentCollection>
<ArcSegment Size="30,30" IsLargeArc="True" SweepDirection="Clockwise" Point="40,40" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="LoadingIndicatorArcsStyle" TargetType="{x:Type networkManager:LoadingIndicator}" BasedOn="{StaticResource LoadingIndicatorArcsStyleKey}"/>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:networkManager="clr-namespace:NETworkManager">
<!--
Source: https://github.com/BornToBeRoot/NETworkManager/issues/2949
-->

<Style x:Key="LoadingIndicatorPulseStyleKey" TargetType="{x:Type networkManager:LoadingIndicator}">
<Setter Property="Foreground" Value="{DynamicResource ResourceKey=MahApps.Brushes.Accent}"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Width" Value="40"/>
<Setter Property="Height" Value="40"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type networkManager:LoadingIndicator}">
<Border x:Name="PART_Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SizeStates">
<VisualState x:Name="Large" />
<VisualState x:Name="Small" />
</VisualStateGroup>
<VisualStateGroup x:Name="ActiveStates">
<VisualState x:Name="Inactive"/>
<VisualState x:Name="Active">
<Storyboard SpeedRatio="{TemplateBinding SpeedRatio}" RepeatBehavior="Forever" Duration="0:0:1.500">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_Ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
<LinearDoubleKeyFrame KeyTime="0:0:0.000" Value="0"/>
<LinearDoubleKeyFrame KeyTime="0:0:1.500" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_Ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)">
<LinearDoubleKeyFrame KeyTime="0:0:0.000" Value="0"/>
<LinearDoubleKeyFrame KeyTime="0:0:1.500" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimation From="1" To="0" Duration="0:0:1.500" Storyboard.TargetName="PART_Ellipse" Storyboard.TargetProperty="(UIElement.Opacity)"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<Grid Background="Transparent">
<Ellipse x:Name="PART_Ellipse" RenderTransformOrigin="0.5,0.5" Fill="{TemplateBinding Foreground}">
<Ellipse.RenderTransform>
<ScaleTransform/>
</Ellipse.RenderTransform>
</Ellipse>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="LoadingIndicatorPulseStyle" TargetType="{x:Type networkManager:LoadingIndicator}" BasedOn="{StaticResource LoadingIndicatorPulseStyleKey}"/>
</ResourceDictionary>
Loading
Loading