From f261f3199f8a6a12af4d894a72792e316336e01b Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Mon, 3 Feb 2020 15:45:57 +0800
Subject: [PATCH] fixed some bugs
---
.../HandyControlDemo_Core30.csproj | 5 +++
.../HandyControlDemo_Net_40.csproj | 5 +++
.../HandyControlDemo_Net_GE45.csproj | 5 +++
.../HandyControlDemo_Shared/App.xaml.cs | 14 +++++++
.../Properties/App.config | 3 ++
.../Resources/Themes/Basic/Brushes.xaml | 18 ++++-----
.../Tools/GeometryAnimationDemoCtl.xaml | 5 ++-
.../Controls/Image/ImageBlock.cs | 35 +++++++++++++++++-
.../Controls/Other/Carousel.cs | 34 ++++++++++++++++-
.../Controls/Other/NotifyIcon.cs | 5 +--
.../Controls/Time/FlipClock/FlipClock.cs | 37 +++++++++++++++++--
11 files changed, 147 insertions(+), 19 deletions(-)
create mode 100644 src/Shared/HandyControlDemo_Shared/Properties/App.config
diff --git a/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj b/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj
index 80a476b3..dc1bfbd0 100644
--- a/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj
+++ b/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj
@@ -483,6 +483,11 @@
Lang.Designer.cs
+
+
+ Properties\App.config
+
+
Data\MessageToken.tt
diff --git a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj
index 98fcf4f6..b869564e 100644
--- a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj
+++ b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj
@@ -419,6 +419,11 @@
Lang.Designer.cs
+
+
+ Properties\App.config
+
+
Resources\fabric-icons.ttf
diff --git a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
index 2fd623be..f61370b1 100644
--- a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
+++ b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
@@ -488,6 +488,11 @@
Designer
+
+
+ Properties\App.config
+
+
Resources\Img\LeftMainContent\RepeatButton_16x.png
diff --git a/src/Shared/HandyControlDemo_Shared/App.xaml.cs b/src/Shared/HandyControlDemo_Shared/App.xaml.cs
index 72e70341..d65ad0ee 100644
--- a/src/Shared/HandyControlDemo_Shared/App.xaml.cs
+++ b/src/Shared/HandyControlDemo_Shared/App.xaml.cs
@@ -3,6 +3,7 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net;
+using System.Runtime;
using System.Security.Authentication;
using System.Threading;
using System.Windows;
@@ -21,6 +22,19 @@ namespace HandyControlDemo
private static Mutex AppMutex;
#pragma warning restore IDE0052
+ public App()
+ {
+#if !netle40
+ var cachePath = $"{AppDomain.CurrentDomain.BaseDirectory}Cache";
+ if (!Directory.Exists(cachePath))
+ {
+ Directory.CreateDirectory(cachePath);
+ }
+ ProfileOptimization.SetProfileRoot(cachePath);
+ ProfileOptimization.StartProfile("Profile");
+#endif
+ }
+
protected override void OnStartup(StartupEventArgs e)
{
AppMutex = new Mutex(true, "HandyControlDemo", out var createdNew);
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/App.config b/src/Shared/HandyControlDemo_Shared/Properties/App.config
new file mode 100644
index 00000000..49cc43e1
--- /dev/null
+++ b/src/Shared/HandyControlDemo_Shared/Properties/App.config
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Resources/Themes/Basic/Brushes.xaml b/src/Shared/HandyControlDemo_Shared/Resources/Themes/Basic/Brushes.xaml
index bcee168f..95654be8 100644
--- a/src/Shared/HandyControlDemo_Shared/Resources/Themes/Basic/Brushes.xaml
+++ b/src/Shared/HandyControlDemo_Shared/Resources/Themes/Basic/Brushes.xaml
@@ -6,7 +6,7 @@
-
+
@@ -21,7 +21,7 @@
-
+
@@ -34,7 +34,7 @@
-
+
@@ -47,7 +47,7 @@
-
+
@@ -59,7 +59,7 @@
-
+
@@ -71,7 +71,7 @@
-
+
@@ -83,7 +83,7 @@
-
+
@@ -95,7 +95,7 @@
-
+
@@ -107,7 +107,7 @@
-
+
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Tools/GeometryAnimationDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Tools/GeometryAnimationDemoCtl.xaml
index ede0f570..bce845a2 100644
--- a/src/Shared/HandyControlDemo_Shared/UserControl/Tools/GeometryAnimationDemoCtl.xaml
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Tools/GeometryAnimationDemoCtl.xaml
@@ -27,7 +27,10 @@
-
+
+
+
+
diff --git a/src/Shared/HandyControl_Shared/Controls/Image/ImageBlock.cs b/src/Shared/HandyControl_Shared/Controls/Image/ImageBlock.cs
index 11f3adcb..1093a4fe 100644
--- a/src/Shared/HandyControl_Shared/Controls/Image/ImageBlock.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Image/ImageBlock.cs
@@ -23,13 +23,46 @@ namespace HandyControl.Controls
private int _blockHeight;
+ private bool _isDisposed;
+
public ImageBlock()
{
_dispatcherTimer = new DispatcherTimer(DispatcherPriority.Render)
{
Interval = Interval
};
- _dispatcherTimer.Tick += DispatcherTimer_Tick;
+
+ IsVisibleChanged += ImageBlock_IsVisibleChanged;
+ }
+
+ ~ImageBlock() => Dispose();
+
+ public void Dispose()
+ {
+ if (_isDisposed) return;
+
+ IsVisibleChanged -= ImageBlock_IsVisibleChanged;
+ _dispatcherTimer.Stop();
+ _isDisposed = true;
+
+ GC.SuppressFinalize(this);
+ }
+
+ private void ImageBlock_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
+ {
+ if(IsVisible)
+ {
+ _dispatcherTimer.Tick += DispatcherTimer_Tick;
+ if (IsPlaying)
+ {
+ _dispatcherTimer.Start();
+ }
+ }
+ else
+ {
+ _dispatcherTimer.Stop();
+ _dispatcherTimer.Tick -= DispatcherTimer_Tick;
+ }
}
private void UpdateDatas()
diff --git a/src/Shared/HandyControl_Shared/Controls/Other/Carousel.cs b/src/Shared/HandyControl_Shared/Controls/Other/Carousel.cs
index 61cc89ad..47ac493a 100644
--- a/src/Shared/HandyControl_Shared/Controls/Other/Carousel.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Other/Carousel.cs
@@ -22,7 +22,7 @@ namespace HandyControl.Controls
[ContentProperty("Items")]
[TemplatePart(Name = ElementPanelPage, Type = typeof(Panel))]
[TemplatePart(Name = ElementItemsControl, Type = typeof(ItemsPresenter))]
- public class Carousel : ListBox
+ public class Carousel : ListBox, IDisposable
{
#region Constants
@@ -33,6 +33,8 @@ namespace HandyControl.Controls
#region Data
+ private bool _isDisposed;
+
private Panel _panelPage;
private bool _appliedTemplate;
@@ -119,6 +121,36 @@ namespace HandyControl.Controls
CommandBindings.Add(new CommandBinding(ControlCommands.Selected, ButtonPages_OnClick));
Loaded += (s, e) => UpdatePageButtons();
+ IsVisibleChanged += Carousel_IsVisibleChanged;
+ }
+
+ ~Carousel() => Dispose();
+
+ public void Dispose()
+ {
+ if (_isDisposed) return;
+
+ IsVisibleChanged -= Carousel_IsVisibleChanged;
+ _updateTimer.Stop();
+ _isDisposed = true;
+
+ GC.SuppressFinalize(this);
+ }
+
+ private void Carousel_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
+ {
+ if (_updateTimer == null) return;
+
+ if (IsVisible)
+ {
+ _updateTimer.Tick += UpdateTimer_Tick;
+ _updateTimer.Start();
+ }
+ else
+ {
+ _updateTimer.Stop();
+ _updateTimer.Tick -= UpdateTimer_Tick;
+ }
}
protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
diff --git a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs
index cd15bd75..6531ccf6 100644
--- a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs
@@ -93,10 +93,7 @@ namespace HandyControl.Controls
if (Application.Current != null) Application.Current.Exit += (s, e) => Dispose();
}
- ~NotifyIcon()
- {
- Dispose(false);
- }
+ ~NotifyIcon() => Dispose(false);
public void Init()
{
diff --git a/src/Shared/HandyControl_Shared/Controls/Time/FlipClock/FlipClock.cs b/src/Shared/HandyControl_Shared/Controls/Time/FlipClock/FlipClock.cs
index bd066e7d..d7d1fc0d 100644
--- a/src/Shared/HandyControl_Shared/Controls/Time/FlipClock/FlipClock.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Time/FlipClock/FlipClock.cs
@@ -8,6 +8,10 @@ namespace HandyControl.Controls
{
public class FlipClock : Control
{
+ private readonly DispatcherTimer _dispatcherTimer;
+
+ private bool _isDisposed;
+
public static readonly DependencyProperty NumberListProperty = DependencyProperty.Register(
"NumberList", typeof(List), typeof(FlipClock), new PropertyMetadata(new List {0, 0, 0, 0, 0, 0}));
@@ -44,12 +48,39 @@ namespace HandyControl.Controls
public FlipClock()
{
- var dispatcherTimer = new DispatcherTimer
+ _dispatcherTimer = new DispatcherTimer(DispatcherPriority.Render)
{
Interval = TimeSpan.FromMilliseconds(200)
};
- dispatcherTimer.Tick += DispatcherTimer_Tick;
- dispatcherTimer.Start();
+
+ IsVisibleChanged += FlipClock_IsVisibleChanged;
+ }
+
+ ~FlipClock() => Dispose();
+
+ public void Dispose()
+ {
+ if (_isDisposed) return;
+
+ IsVisibleChanged -= FlipClock_IsVisibleChanged;
+ _dispatcherTimer.Stop();
+ _isDisposed = true;
+
+ GC.SuppressFinalize(this);
+ }
+
+ private void FlipClock_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
+ {
+ if (IsVisible)
+ {
+ _dispatcherTimer.Tick += DispatcherTimer_Tick;
+ _dispatcherTimer.Start();
+ }
+ else
+ {
+ _dispatcherTimer.Stop();
+ _dispatcherTimer.Tick -= DispatcherTimer_Tick;
+ }
}
private void DispatcherTimer_Tick(object sender, EventArgs e) => DisplayTime = DateTime.Now;