blob: e810cc8e5b58b47d1b23f93119dbd2ae4111319c (
plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
using ElmSharp;
using System.Collections.Generic;
namespace Xamarin.Forms.Platform.Tizen
{
public class ImageCellRenderer : TextCellRenderer
{
const int _defaultHeight = 55;
Dictionary<EvasObject, Native.Image> _realizedViews = new Dictionary<EvasObject, Native.Image>();
public ImageCellRenderer() : this("default")
{
ImagePart = "elm.swallow.icon";
}
protected ImageCellRenderer(string style) : base(style) { }
protected string ImagePart { get; set; }
protected override EvasObject OnGetContent(Cell cell, string part)
{
if (part == ImagePart)
{
var imgCell = cell as ImageCell;
int pixelSize = Forms.ConvertToScaledPixel(imgCell.RenderHeight);
if (pixelSize <= 0)
{
pixelSize = Forms.ConvertToPixel(_defaultHeight);
}
var image = new Native.Image(Forms.Context.MainWindow)
{
MinimumWidth = pixelSize,
MinimumHeight = pixelSize
};
image.SetAlignment(-1.0, -1.0); // fill
image.SetWeight(1.0, 1.0); // expand
var task = image.LoadFromImageSourceAsync(imgCell.ImageSource);
return image;
}
else
{
return null;
}
}
protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
{
if (property == ImageCell.ImageSourceProperty.PropertyName)
{
EvasObject image;
realizedView.TryGetValue(ImagePart, out image);
(image as Native.Image)?.LoadFromImageSourceAsync((cell as ImageCell)?.ImageSource);
return false;
}
return base.OnCellPropertyChanged(cell, property, realizedView);
}
}
}
|