fixed some bugs

This commit is contained in:
NaBian committed 2020-02-03 15:45:57 +08:00
1 parent 203fbb4541
commit f261f3199f
11 files changed
+147 -19

No files matched your search

@@ -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)
@@ -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()
{