-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for existing IImage loading in AdvancedImage. Close #17
- Loading branch information
Showing
4 changed files
with
98 additions
and
14 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
AsyncImageLoader.Avalonia.Demo/Converters/GetClassNameConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Globalization; | ||
using Avalonia.Data.Converters; | ||
|
||
namespace AsyncImageLoader.Avalonia.Demo.Converters; | ||
|
||
public class GetClassNameConverter : IValueConverter { | ||
public static GetClassNameConverter Instance { get; } = new(); | ||
|
||
/// <inheritdoc /> | ||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { | ||
if (value is null) { | ||
return "null"; | ||
} | ||
|
||
return value.GetType().Name; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { | ||
throw new NotSupportedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 15 additions & 8 deletions
23
AsyncImageLoader.Avalonia.Demo/Pages/AdvancedImagePage.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
using Avalonia; | ||
using System; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Markup.Xaml; | ||
using Avalonia.Media.Imaging; | ||
using Avalonia.Platform; | ||
|
||
namespace AsyncImageLoader.Avalonia.Demo.Pages { | ||
public partial class AdvancedImagePage : UserControl { | ||
public AdvancedImagePage() { | ||
InitializeComponent(); | ||
} | ||
|
||
private void InitializeComponent() { | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
private void ReloadButton_OnClick(object? sender, RoutedEventArgs e) { | ||
var advancedImage = this.FindControl<AdvancedImage>("ReloadableAdvancedImage"); | ||
advancedImage.Source = null; | ||
advancedImage.Source = "https://github.com/AvaloniaUtils/AsyncImageLoader.Avalonia/raw/master/AsyncImageLoader.Avalonia.Demo/Assets/cat0.jpg"; | ||
ReloadableAdvancedImage.Source = null; | ||
ReloadableAdvancedImage.Source = "https://github.com/AvaloniaUtils/AsyncImageLoader.Avalonia/raw/master/AsyncImageLoader.Avalonia.Demo/Assets/cat0.jpg"; | ||
} | ||
|
||
private void SetSourceButton_OnClick(object? sender, RoutedEventArgs e) { | ||
CurrentImageExample.Source = "/Assets/cat5.jpg"; | ||
} | ||
|
||
private void SetCurrentImageButton_OnClick(object? sender, RoutedEventArgs e) { | ||
using var stream = AssetLoader.Open(new Uri("avares://AsyncImageLoader.Avalonia.Demo/Assets/cat4.jpg", UriKind.RelativeOrAbsolute)); | ||
CurrentImageExample.CurrentImage = new Bitmap(stream); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters