-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoViewModel.cs
36 lines (25 loc) · 1.04 KB
/
DemoViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Collections.ObjectModel;
using Microsoft.Toolkit.Mvvm.ComponentModel;
namespace MauiAppImageSourceFromFileBug
{
public partial class DemoViewModel : ObservableObject
{
[ObservableProperty]
private ViewModelItem _selectedItem;
public DemoViewModel()
{
var filePath = Path.Combine(FileSystem.AppDataDirectory, "test.png");
// Prepare the test file
var imageBytes = ImageResource.test;
File.WriteAllBytes(filePath, imageBytes);
// Actual test code
var imageSource = ImageSource.FromFile(filePath);
// Workaround: Comment the above line and use this instead, no more exception
//var imageSource = ImageSource.FromStream(() => File.OpenRead(filePath));
var demoItem = new ViewModelItem(filePath, imageSource);
Items.Add(demoItem);
Items.Add(new ViewModelItem("- Empty - ", null));
}
public ObservableCollection<ViewModelItem> Items { get; } = new();
}
}