public class DossierViewCell : ViewCell
{
private CachedImage cachedImage;
private Label label;
private Frame frame;
public DossierViewCell()
{
this.frame = new Frame()
{
Margin = 0,
Padding = new Thickness(8, 5, 5, 5),
BackgroundColor = Statics.Palette.White,
CornerRadius = 0,
BorderColor = Statics.Palette.DarkBeige
};
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = 40 });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Star });
// Set placeholder image that will be shown when image is loading or when downloading failed
var placeholderImage = Device.RuntimePlatform == Device.UWP ? "Assets\\dossier.png" : "dossier";
// Create image which will hold the logo of the organisation
this.cachedImage = new CachedImage()
{
Aspect = Aspect.AspectFit,
DownsampleToViewSize = true,
DownsampleUseDipUnits = true,
HeightRequest = 40,
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
WidthRequest = 40,
LoadingPlaceholder = placeholderImage,
ErrorPlaceholder = placeholderImage,
};
// Indicate where the image will be positioned in the grid
Grid.SetColumn(this.cachedImage, 0);
// Create labels which will hold the name, roles and organisation
this.label = new Label()
{
Margin = new Thickness(15, 0, 0, 0),
FontSize = 20,
TextColor = Statics.Palette.DarkGray,
VerticalOptions = LayoutOptions.CenterAndExpand
};
// Indicate where the stackpanel will be positioned in the grid
Grid.SetColumn(this.label, 1);
// Create arrow image
var image = new Image()
{
HeightRequest = 30,
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
WidthRequest = 30,
Source = Device.RuntimePlatform == Device.UWP ? "Assets\\arrow_right.png" : "arrow_right"
};
Grid.SetColumn(image, 1);
// Add images and stacklayout to grid
grid.Children.Add(this.cachedImage);
grid.Children.Add(this.label);
grid.Children.Add(image);
// Add grid to frame so we can show the content
frame.Content = grid;
// Add frame to ViewCell View
this.View = frame;
this.View.BindingContextChanged += View_BindingContextChanged;
}
private void View_BindingContextChanged(object sender, System.EventArgs e)
{
// Remove old image
this.cachedImage.Source = null;
var frame = sender as Frame;
if (frame == null)
return;
var dossier = frame.BindingContext as Dossier;
if (dossier == null)
return;
this.cachedImage.Source = dossier.ThumbnailUrl;
this.label.Text = dossier.Title;
}
}