1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-01 08:03:37 +00:00

bind to image with OnBindingContextChanged

This commit is contained in:
Kyle Spearrin
2017-10-20 23:08:39 -04:00
parent 6ba396440f
commit 7c56f1a773
8 changed files with 42 additions and 29 deletions

View File

@@ -7,21 +7,19 @@ namespace Bit.App.Controls
{
public class VaultListViewCell : LabeledDetailCell
{
public static readonly BindableProperty LoginParameterProperty = BindableProperty.Create(nameof(LoginParameter),
public static readonly BindableProperty CipherParameterProperty = BindableProperty.Create(nameof(CipherParameter),
typeof(VaultListPageModel.Cipher), typeof(VaultListViewCell), null);
public VaultListViewCell(Action<VaultListPageModel.Cipher> moreClickedAction)
{
SetBinding(LoginParameterProperty, new Binding("."));
Icon.SetBinding(CachedImage.SourceProperty, nameof(VaultListPageModel.Cipher.Icon));
Icon.SetBinding(CachedImage.LoadingPlaceholderProperty, nameof(VaultListPageModel.Cipher.Icon));
SetBinding(CipherParameterProperty, new Binding("."));
Label.SetBinding(Label.TextProperty, nameof(VaultListPageModel.Cipher.Name));
Detail.SetBinding(Label.TextProperty, nameof(VaultListPageModel.Cipher.Subtitle));
LabelIcon.SetBinding(VisualElement.IsVisibleProperty, nameof(VaultListPageModel.Cipher.Shared));
LabelIcon2.SetBinding(VisualElement.IsVisibleProperty, nameof(VaultListPageModel.Cipher.HasAttachments));
Button.Image = "more.png";
Button.Command = new Command(() => moreClickedAction?.Invoke(LoginParameter));
Button.Command = new Command(() => moreClickedAction?.Invoke(CipherParameter));
Button.BackgroundColor = Color.Transparent;
LabelIcon.Source = "share.png";
@@ -30,10 +28,25 @@ namespace Bit.App.Controls
BackgroundColor = Color.White;
}
public VaultListPageModel.Cipher LoginParameter
public VaultListPageModel.Cipher CipherParameter
{
get { return GetValue(LoginParameterProperty) as VaultListPageModel.Cipher; }
set { SetValue(LoginParameterProperty, value); }
get { return GetValue(CipherParameterProperty) as VaultListPageModel.Cipher; }
set { SetValue(CipherParameterProperty, value); }
}
protected override void OnBindingContextChanged()
{
Icon.Source = null;
if(BindingContext is VaultListPageModel.Cipher item)
{
Icon.Source = item.Icon;
if(item.Type == Enums.CipherType.Login)
{
Icon.LoadingPlaceholder = "login.png";
}
}
base.OnBindingContextChanged();
}
}
}