diff --git a/ImageEx/DependencyObjectExtensions.cs b/ImageEx/DependencyObjectExtensions.cs
index fb539f8..7d89459 100644
--- a/ImageEx/DependencyObjectExtensions.cs
+++ b/ImageEx/DependencyObjectExtensions.cs
@@ -8,9 +8,9 @@ public static class DependencyObjectExtensions
/// Find all ascendant elements of the specified element. This method can be chained with
/// LINQ calls to add additional filters or projections on top of the returned results.
///
- /// This method is meant to provide extra flexibility in specific scenarios and it should not
+ /// This method is meant to provide extra flexibility in specific scenarios, and it should not
/// be used when only the first item is being looked for. In those cases, use one of the
- /// available overloads instead, which will
+ /// available overloads instead, which will
/// offer a more compact syntax as well as better performance in those cases.
///
///
diff --git a/ImageEx/ImageEx.cs b/ImageEx/ImageEx.cs
index 1a20c18..130d03f 100644
--- a/ImageEx/ImageEx.cs
+++ b/ImageEx/ImageEx.cs
@@ -17,7 +17,6 @@ public partial class ImageEx : ImageExBase
/// Initializes a new instance of the class.
///
public ImageEx()
- : base()
{
DefaultStyleKey = typeof(ImageEx);
Debug.WriteLine(DefaultStyleKey.ToString());
diff --git a/ImageEx/ImageExBase.Members.cs b/ImageEx/ImageExBase.Members.cs
index f536ea2..be7664a 100644
--- a/ImageEx/ImageExBase.Members.cs
+++ b/ImageEx/ImageExBase.Members.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+// ReSharper disable MemberCanBePrivate.Global
namespace ImageEx
{
///
@@ -62,6 +63,7 @@ public partial class ImageExBase
///
/// Gets a value indicating whether control has been initialized.
///
+ // ReSharper disable once MemberCanBeProtected.Global
public bool IsInitialized { get; private set; }
///
@@ -101,7 +103,7 @@ public Stretch Stretch
}
///
- /// Gets or sets a value indicating whether gets or sets cache state
+ /// Gets or sets a value indicating whether it gets or sets cache state
///
public bool IsCacheEnabled
{
@@ -110,7 +112,7 @@ public bool IsCacheEnabled
}
///
- /// Gets or sets a value indicating whether gets or sets is lazy loading enable. (17763 or higher supported)
+ /// Gets or sets a value indicating whether it gets or sets is lazy loading enable. (17763 or higher supported)
///
/// Windows 10 build 17763 or higher required.
public bool EnableLazyLoading
@@ -148,7 +150,7 @@ private static void EnableLazyLoadingChanged(DependencyObject d, DependencyPrope
private static void LazyLoadingThresholdChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
- if (d is ImageExBase control && control.EnableLazyLoading)
+ if (d is ImageExBase { EnableLazyLoading: true } control)
{
control.InvalidateLazyLoading();
}
diff --git a/ImageEx/ImageExBase.Source.cs b/ImageEx/ImageExBase.Source.cs
index 718817c..efe6525 100644
--- a/ImageEx/ImageExBase.Source.cs
+++ b/ImageEx/ImageExBase.Source.cs
@@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Diagnostics;
-
namespace ImageEx
{
///
@@ -27,7 +25,7 @@ public partial class ImageExBase
public object Source
{
get { return GetValue(SourceProperty); }
- set { Debug.WriteLine("test3"); SetValue(SourceProperty, value); }
+ set { SetValue(SourceProperty, value); }
}
private static void SourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
@@ -85,19 +83,17 @@ private void AttachSource(ImageSource source)
VisualStateManager.GoToState(this, LoadedState, true);
ImageExOpened?.Invoke(this, new ImageExOpenedEventArgs());
}
- Debug.WriteLine("test4");
}
private async void SetSource(object source)
{
- Debug.WriteLine("test5_1");
if (!IsInitialized)
{
return;
}
-
- Debug.WriteLine("test5_2");
- _tokenSource?.Cancel();
+
+ if (_tokenSource is { Token.IsCancellationRequested: false })
+ await _tokenSource?.CancelAsync()!;
_tokenSource = new CancellationTokenSource();
@@ -108,10 +104,7 @@ private async void SetSource(object source)
return;
}
- Debug.WriteLine("test5_3");
-
VisualStateManager.GoToState(this, LoadingState, true);
-
var imageSource = source as ImageSource;
if (imageSource != null)
{
@@ -119,7 +112,6 @@ private async void SetSource(object source)
return;
}
- Debug.WriteLine("test5_4");
var uri = source as Uri;
if (uri == null)
{
@@ -131,14 +123,12 @@ private async void SetSource(object source)
return;
}
}
-
- Debug.WriteLine("test5_6");
+
if (!IsHttpUri(uri) && !uri.IsAbsoluteUri)
{
uri = new Uri("ms-appx:///" + uri.OriginalString.TrimStart('/'));
}
-
- Debug.WriteLine("test5_7");
+
try
{
await LoadImageAsync(uri, _tokenSource.Token);
@@ -152,8 +142,6 @@ private async void SetSource(object source)
VisualStateManager.GoToState(this, FailedState, true);
ImageExFailed?.Invoke(this, new ImageExFailedEventArgs(e));
}
-
- Debug.WriteLine("test5");
}
private async Task LoadImageAsync(Uri imageUri, CancellationToken token)
@@ -174,7 +162,7 @@ private async Task LoadImageAsync(Uri imageUri, CancellationToken token)
{
var source = imageUri.OriginalString;
const string base64Head = "base64,";
- var index = source.IndexOf(base64Head);
+ var index = source.IndexOf(base64Head, StringComparison.OrdinalIgnoreCase);
if (index >= 0)
{
var bytes = Convert.FromBase64String(source.Substring(index + base64Head.Length));
@@ -199,13 +187,11 @@ private async Task LoadImageAsync(Uri imageUri, CancellationToken token)
///
/// This method is provided in case a developer would like their own custom caching strategy for .
- /// By default it uses the built-in UWP cache provided by and
+ /// By default, it uses the built-in UWP cache provided by and
/// the control itself. This method should return an
/// value of the image specified by the provided uri parameter.
/// A is provided in case the current request is invalidated
- /// (e.g. the container is recycled before the original image is loaded).
- /// The Toolkit also has an image cache helper which can be used as well:
- /// in .
+ /// (e.g. the container is recycled before the original image loaded).
///
///
///
@@ -234,7 +220,7 @@ private async Task LoadImageAsync(Uri imageUri, CancellationToken token)
///
protected virtual Task ProvideCachedResourceAsync(Uri imageUri, CancellationToken token)
{
- // By default we just use the built-in UWP image cache provided within the Image control.
+ // By default, we just use the built-in UWP image cache provided within the Image control.
return Task.FromResult((ImageSource)new BitmapImage(imageUri));
}
}
diff --git a/ImageEx/ImageExBase.cs b/ImageEx/ImageExBase.cs
index f50b9fd..5ec2455 100644
--- a/ImageEx/ImageExBase.cs
+++ b/ImageEx/ImageExBase.cs
@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Diagnostics;
+// ReSharper disable MemberCanBePrivate.Global
namespace ImageEx
{
@@ -80,10 +80,8 @@ public abstract partial class ImageExBase : Control
///
/// Initializes a new instance of the class.
///
- public ImageExBase()
- {
- Debug.WriteLine("test2");
- }
+ // ReSharper disable once PublicConstructorInAbstractClass
+ public ImageExBase() { }
///
/// Attach image opened event handler
@@ -157,7 +155,7 @@ protected override void OnApplyTemplate()
RemoveImageOpened(OnImageOpened);
RemoveImageFailed(OnImageFailed);
- Image = GetTemplateChild(PartImage) as object;
+ Image = GetTemplateChild(PartImage);
IsInitialized = true;
diff --git a/ImageEx/Themes/Generic.xaml b/ImageEx/Themes/Generic.xaml
index 5877125..d7aea46 100644
--- a/ImageEx/Themes/Generic.xaml
+++ b/ImageEx/Themes/Generic.xaml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/ImageEx/Usings.cs b/ImageEx/Usings.cs
index 7aeee45..b55c76b 100644
--- a/ImageEx/Usings.cs
+++ b/ImageEx/Usings.cs
@@ -19,7 +19,6 @@
#endif
#if NETCOREAPP
-global using Microsoft.UI.Composition;
global using Microsoft.UI.Xaml;
global using Microsoft.UI.Xaml.Controls;
global using Microsoft.UI.Xaml.Media;