protected override void OnPropertyChanged([CallerMemberName] string propertyName = null) { if (this.initialized) { switch (propertyName) { case nameof(this.Text): case nameof(this.EmptyText): this.lblText.Text = !string.IsNullOrEmpty(this.Text) ? this.Text : this.EmptyText; break; case nameof(this.TextColor): this.lblText.TextColor = this.TextColor; break; case nameof(this.FontSize): this.lblText.FontSize = this.FontSize; break; case nameof(this.FontFamily): this.lblText.FontFamily = this.FontFamily; this.lblLabel.FontFamily = this.FontFamily; this.lblAssistive.FontFamily = this.FontFamily; break; case nameof(this.LabelText): this.lblLabel.Text = this.LabelText; break; case nameof(this.LabelTextColor): this.lblLabel.TextColor = this.LabelTextColor; break; case nameof(this.LabelSize): this.lblLabel.FontSize = this.LabelSize; break; case nameof(this.AssistiveText): this.lblAssistive.Text = this.AssistiveText; break; case nameof(this.AssistiveTextColor): this.lblAssistive.TextColor = this.AssistiveTextColor; break; case nameof(this.AssistiveSize): this.lblAssistive.FontSize = this.AssistiveSize; break; case nameof(LeadingIcon): if (!string.IsNullOrEmpty(LeadingIcon)) { imgLeadingIcon.SetImage(LeadingIcon); } imgLeadingIcon.IsVisible = LeadingIconIsVisible; if (LeadingIconIsVisible) { lblLabel.Margin = new Thickness(36, 0, 0, 0); lblAssistive.Margin = new Thickness(36, 0, 0, 0); } break; case nameof(CustomLeadingIcon): if (CustomLeadingIcon != null) { imgLeadingIcon.SetCustomImage(CustomLeadingIcon); } imgLeadingIcon.IsVisible = LeadingIconIsVisible; if (LeadingIconIsVisible) { lblLabel.Margin = new Thickness(36, 0, 0, 0); lblAssistive.Margin = new Thickness(36, 0, 0, 0); } break; case nameof(TrailingIcon): if (!string.IsNullOrEmpty(TrailingIcon)) { imgTrailingIcon.SetImage(TrailingIcon); } imgTrailingIcon.IsVisible = TrailingIconIsVisible; break; case nameof(CustomTrailingIcon): if (CustomTrailingIcon != null) { imgTrailingIcon.SetCustomImage(CustomTrailingIcon); } imgTrailingIcon.IsVisible = TrailingIconIsVisible; break; } } }
protected void UpdateLayout(string propertyName, Label lblLabel, Label lblAssistive, Frame frmContainer, BoxView bxvLine, CustomImageButton imgLeadingIcon, CustomImageButton imgTrailingIcon) { switch (propertyName) { case nameof(IsEnabled): SetIsEnabled(); SetTextColor(); SetLabelTextColor(lblLabel); SetBorderAndBackgroundColors(frmContainer, bxvLine); break; case nameof(TextColor): SetTextColor(); break; case nameof(FontSize): SetFontSize(); break; case nameof(FontFamily): case nameof(LabelFontFamily): case nameof(AssistiveFontFamily): SetFontFamily(); if (LabelFontFamily != null) { lblLabel.FontFamily = LabelFontFamily; } else if (LabelFontFamily == null && FontFamily != null) { lblLabel.FontFamily = FontFamily; } if (AssistiveFontFamily != null) { lblAssistive.FontFamily = AssistiveFontFamily; } else if (AssistiveFontFamily == null && FontFamily != null) { lblAssistive.FontFamily = FontFamily; } //lblLabel.FontFamily = FontFamily; //lblAssistive.FontFamily = FontFamily; break; case nameof(Placeholder): SetPlaceholder(); break; case nameof(PlaceholderColor): SetPlaceholderColor(); break; case nameof(LabelText): lblLabel.Text = LabelText; lblLabel.IsVisible = !string.IsNullOrEmpty(LabelText); break; case nameof(LabelTextColor): SetLabelTextColor(lblLabel); break; case nameof(LabelSize): lblLabel.FontSize = LabelSize; break; case nameof(LabelMargin): lblLabel.Margin = LabelMargin; break; case nameof(Padding): SetPadding(); break; case nameof(CornerRadius): frmContainer.CornerRadius = Convert.ToInt32(CornerRadius); break; case nameof(Type): case nameof(BackgroundColor): case nameof(BorderColor): SetBorderAndBackgroundColors(frmContainer, bxvLine); if (Type == FieldTypes.Lined) { frmContainer.HeightRequest = 30; if (LeadingIconIsVisible) { lblLabel.Margin = new Thickness(36, lblLabel.Margin.Top, lblLabel.Margin.Right, 0); frmContainer.Padding = new Thickness(0); lblAssistive.Margin = new Thickness(36, lblAssistive.Margin.Top, lblAssistive.Margin.Right, lblAssistive.Margin.Bottom); bxvLine.Margin = new Thickness(36, 0, 0, 0); } else { lblLabel.Margin = new Thickness(0, lblLabel.Margin.Top, 0, 0); frmContainer.Padding = new Thickness(0); lblAssistive.Margin = new Thickness(0, lblAssistive.Margin.Top, 0, lblAssistive.Margin.Bottom); } } break; case nameof(AssistiveText): lblAssistive.Text = AssistiveText; lblAssistive.IsVisible = !string.IsNullOrEmpty(AssistiveText); if (AnimateError && !string.IsNullOrEmpty(AssistiveText)) { ShakeAnimation.Animate(this); } break; case nameof(AssistiveTextColor): lblAssistive.TextColor = AssistiveTextColor; break; case nameof(AssistiveSize): lblAssistive.FontSize = AssistiveSize; break; case nameof(AssistiveMargin): lblAssistive.Margin = AssistiveMargin; break; case nameof(LeadingIcon): if (!string.IsNullOrEmpty(LeadingIcon)) { imgLeadingIcon.SetImage(LeadingIcon); } imgLeadingIcon.IsVisible = LeadingIconIsVisible; break; case nameof(CustomLeadingIcon): if (CustomLeadingIcon != null) { imgLeadingIcon.SetCustomImage(CustomLeadingIcon); } imgLeadingIcon.IsVisible = LeadingIconIsVisible; break; case nameof(LeadingIconCommand): if (LeadingIconCommand != null) { imgLeadingIcon.Tapped = () => { if (LeadingIconCommand != null) { LeadingIconCommand.Execute(LeadingIconCommandParameter); } }; } break; case nameof(TrailingIcon): if (!string.IsNullOrEmpty(TrailingIcon)) { imgTrailingIcon.SetImage(TrailingIcon); } imgTrailingIcon.IsVisible = TrailingIconIsVisible; break; case nameof(CustomTrailingIcon): if (CustomTrailingIcon != null) { imgTrailingIcon.SetCustomImage(CustomTrailingIcon); } imgTrailingIcon.IsVisible = TrailingIconIsVisible; break; case nameof(TrailingIconCommand): if (TrailingIconCommand != null) { imgTrailingIcon.Tapped = () => { if (TrailingIconCommand != null) { TrailingIconCommand.Execute(TrailingIconCommandParameter); } }; } break; case nameof(FieldHeightRequest): frmContainer.HeightRequest = FieldHeightRequest; break; case nameof(HorizontalTextAlignment): SetHorizontalTextAlignment(); lblLabel.HorizontalTextAlignment = HorizontalTextAlignment; lblAssistive.HorizontalTextAlignment = HorizontalTextAlignment; break; } }