diff --git a/Telegram/Controls/DownloadsIndicator.cs b/Telegram/Controls/DownloadsIndicator.cs
index 54d091b6b..9213c5dcf 100644
--- a/Telegram/Controls/DownloadsIndicator.cs
+++ b/Telegram/Controls/DownloadsIndicator.cs
@@ -34,6 +34,8 @@ enum State
private State _state;
+ private ProgressBarRing ProgressBar;
+
public DownloadsIndicator()
{
DefaultStyleKey = typeof(DownloadsIndicator);
@@ -73,6 +75,8 @@ public DownloadsIndicator()
protected override void OnApplyTemplate()
{
+ ProgressBar = GetTemplateChild(nameof(ProgressBar)) as ProgressBarRing;
+
var target = GetTemplateChild("Target") as FrameworkElement;
if (target != null)
{
@@ -133,22 +137,20 @@ private CompositionScopedBatch PrepareBatch()
#region Progress
+ private double _progress;
public double Progress
{
- get { return (double)GetValue(ProgressProperty); }
- set { SetValue(ProgressProperty, value); }
+ get => _progress;
+ set => OnProgressChanged(_progress, _progress = value);
}
- public static readonly DependencyProperty ProgressProperty =
- DependencyProperty.Register("Progress", typeof(double), typeof(DownloadsIndicator), new PropertyMetadata(0d, OnProgressChanged));
-
- private static void OnProgressChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ private void OnProgressChanged(double oldValue, double newValue)
{
- ((DownloadsIndicator)d).OnProgressChanged((double)e.NewValue, (double)e.OldValue);
- }
+ if (ProgressBar != null)
+ {
+ ProgressBar.Value = newValue;
+ }
- private void OnProgressChanged(double newValue, double oldValue)
- {
if (newValue == 0 && _state != State.Normal)
{
_state = State.Normal;
diff --git a/Telegram/Controls/FileButton.cs b/Telegram/Controls/FileButton.cs
index ebf19baf1..838c44e69 100644
--- a/Telegram/Controls/FileButton.cs
+++ b/Telegram/Controls/FileButton.cs
@@ -39,6 +39,8 @@ public partial class FileButton : GlyphHyperlinkButton
{
private Grid RootGrid;
+ private ProgressBarRing ProgressBar;
+
private TextBlock ContentPresenter1;
private TextBlock ContentPresenter2;
private TextBlock _label;
@@ -69,6 +71,8 @@ protected override void OnApplyTemplate()
{
RootGrid = GetTemplateChild(nameof(RootGrid)) as Grid;
+ ProgressBar = GetTemplateChild(nameof(ProgressBar)) as ProgressBarRing;
+
ContentPresenter1 = GetTemplateChild(nameof(ContentPresenter1)) as TextBlock;
ContentPresenter2 = GetTemplateChild(nameof(ContentPresenter2)) as TextBlock;
@@ -76,31 +80,13 @@ protected override void OnApplyTemplate()
ContentPresenter2.Text = string.Empty;
_label = ContentPresenter1;
- }
-
- #region Progress
- public double InternalProgress
- {
- get => (double)GetValue(InternalProgressProperty);
- set
+ if (ProgressBar != null)
{
- try
- {
- SetValue(InternalProgressProperty, value);
- }
- catch
- {
- // All the remote procedure calls must be wrapped in a try-catch block
- }
+ ProgressBar.Value = _enqueuedProgress;
}
}
- public static readonly DependencyProperty InternalProgressProperty =
- DependencyProperty.Register("InternalProgress", typeof(double), typeof(FileButton), new PropertyMetadata(0.0));
-
- #endregion
-
#region ProgressVisibility
public Visibility ProgressVisibility
@@ -118,17 +104,17 @@ public double Progress
{
set
{
- if (_shouldEnqueueProgress || !IsConnected)
+ if (_shouldEnqueueProgress || ProgressBar == null || !IsConnected)
{
_enqueuedProgress = value;
}
else if (_state is MessageContentState.Downloading or MessageContentState.Uploading)
{
- InternalProgress = Math.Max(0.05, value);
+ ProgressBar.Value = Math.Max(0.05, value);
}
else
{
- InternalProgress = value;
+ ProgressBar.Value = value;
}
}
}
@@ -376,10 +362,10 @@ private void OnDownloadingCompleted(object sender, CompositionBatchCompletedEven
{
try
{
- if (_state == MessageContentState.Downloading && IsConnected)
+ if (_state == MessageContentState.Downloading && ProgressBar != null && IsConnected)
{
OnGlyphChanged(Icons.Cancel, Icons.ArrowDownload, true, Strings.AccActionCancelDownload, false);
- InternalProgress = _enqueuedProgress;
+ ProgressBar.Value = _enqueuedProgress;
}
_shouldEnqueueProgress = false;
diff --git a/Telegram/Controls/ProgressBarRing.cs b/Telegram/Controls/ProgressBarRing.cs
index 501a5ce96..c9ed0c794 100644
--- a/Telegram/Controls/ProgressBarRing.cs
+++ b/Telegram/Controls/ProgressBarRing.cs
@@ -16,7 +16,7 @@
namespace Telegram.Controls
{
- public partial class ProgressBarRing : ProgressBar
+ public partial class ProgressBarRing : Control
{
private readonly FrameworkElementState _manager;
@@ -124,7 +124,14 @@ private void OnUnloaded(object sender, RoutedEventArgs e)
}
}
- protected override void OnValueChanged(double oldValue, double newValue)
+ private double _value;
+ public double Value
+ {
+ get => _value;
+ set => OnValueChanged(_value, _value = value);
+ }
+
+ private void OnValueChanged(double oldValue, double newValue)
{
if (double.IsNaN(newValue))
{
diff --git a/Telegram/Themes/Accent.xaml b/Telegram/Themes/Accent.xaml
index add701f55..08a1c5e79 100644
--- a/Telegram/Themes/Accent.xaml
+++ b/Telegram/Themes/Accent.xaml
@@ -205,9 +205,9 @@
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
AutomationProperties.AccessibilityView="Raw" />
-
@@ -327,13 +327,13 @@
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
AutomationProperties.AccessibilityView="Raw" />
-
@@ -478,9 +478,9 @@
-
@@ -604,9 +604,9 @@
VerticalAlignment="Center"
AutomationProperties.AccessibilityView="Raw"
Text="{TemplateBinding Glyph}" />
-
-
-
-