public void UpdateDrawerIcon(ImageSource source) { if (source == null) { _drawerIcon.LoadFromImageSourceAsync(ImageSource.FromResource(DefaultIcon, GetType().Assembly)); } else { _drawerIconBox.UnPack(_drawerIcon); _drawerIcon.Unrealize(); _drawerIcon = new EImage(this) { AlignmentY = -1, AlignmentX = -1, WeightX = 1, WeightY = 1 }; _drawerIcon.Show(); _drawerIconBox.PackEnd(_drawerIcon); if (source is FileImageSource fsource) { _drawerIcon.Load(fsource.ToAbsPath()); } else { _drawerIcon.LoadFromImageSourceAsync(source); } } }
EvasObject GetContent(object data, string part) { ShellSection section = data as ShellSection; var box = new EBox(Forms.NativeParent); box.Show(); EImage icon = null; if (section.Icon != null) { icon = new EImage(Forms.NativeParent); icon.Show(); box.PackEnd(icon); _ = icon.LoadFromImageSourceAsync(section.Icon); } var title = new Native.Label(Forms.NativeParent) { Text = section.Title, FontSize = Forms.ConvertToEflFontPoint(14), HorizontalTextAlignment = Native.TextAlignment.Start, VerticalTextAlignment = Native.TextAlignment.Center, }; title.Show(); box.PackEnd(title); int iconPadding = Forms.ConvertToScaledPixel(this.GetIconPadding()); int iconSize = Forms.ConvertToScaledPixel(this.GetIconSize()); int cellHeight = iconPadding * 2 + iconSize; box.SetLayoutCallback(() => { var bound = box.Geometry; int leftMargin = iconPadding; if (icon != null) { var iconBound = bound; iconBound.X += iconPadding; iconBound.Y += iconPadding; iconBound.Width = iconSize; iconBound.Height = iconSize; icon.Geometry = iconBound; leftMargin = (2 * iconPadding + iconSize); } bound.X += leftMargin; bound.Width -= leftMargin; title.Geometry = bound; }); box.MinimumHeight = cellHeight; return(box); }