protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (!this.initialized)
            {
                this.initialized = true;
                this.InitializeComponent();
            }

            switch (propertyName)
            {
            case nameof(base.TranslationX):
                base.OnPropertyChanged(propertyName);
                break;

            case nameof(CustomControl):
                cntCustomControl.Content = CustomControl;
                break;

            case nameof(FontFamily):
                lblLabel.FontFamily     = FontFamily;
                lblAssistive.FontFamily = FontFamily;
                break;

            case nameof(HorizontalTextAlignment):
                lblLabel.HorizontalTextAlignment     = HorizontalTextAlignment;
                lblAssistive.HorizontalTextAlignment = HorizontalTextAlignment;
                break;

            case nameof(this.LabelText):
                this.lblLabel.Text      = this.LabelText;
                this.lblLabel.IsVisible = !string.IsNullOrEmpty(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;
                this.lblAssistive.IsVisible = !string.IsNullOrEmpty(this.AssistiveText);
                if (this.AnimateError && !string.IsNullOrEmpty(this.AssistiveText))
                {
                    ShakeAnimation.Animate(this);
                }
                break;

            case nameof(this.AssistiveTextColor):
                this.lblAssistive.TextColor = this.AssistiveTextColor;
                break;

            case nameof(this.AssistiveSize):
                this.lblAssistive.FontSize = this.AssistiveSize;
                break;
            }
        }
        private static bool OnAssistiveTextValidate(BindableObject bindable, object value)
        {
            var control = (MaterialSlider)bindable;

            // Used to animate the error when the assistive text doesn't change
            if (control.AnimateError && !string.IsNullOrEmpty(control.AssistiveText) && control.AssistiveText == (string)value)
            {
                ShakeAnimation.Animate(control);
            }

            return(true);
        }
        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (!this.initialized)
            {
                this.InitializeComponent();
                this.initialized = true;
            }

            switch (propertyName)
            {
            case nameof(base.TranslationX):
                base.OnPropertyChanged(propertyName);
                break;

            case nameof(this.LabelText):
                this.lblLabel.Text      = this.LabelText;
                this.lblLabel.IsVisible = !string.IsNullOrEmpty(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.Padding):
                this.stcContainer.Padding = this.Padding;
                break;

            case nameof(this.AssistiveText):
                this.lblAssistive.Text      = this.AssistiveText;
                this.lblAssistive.IsVisible = !string.IsNullOrEmpty(this.AssistiveText);
                if (this.AnimateError && !string.IsNullOrEmpty(this.AssistiveText))
                {
                    ShakeAnimation.Animate(this);
                }
                break;

            case nameof(this.AssistiveTextColor):
                this.lblAssistive.TextColor = this.AssistiveTextColor;
                break;

            case nameof(this.AssistiveSize):
                this.lblAssistive.FontSize = this.AssistiveSize;
                break;
            }
        }
        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (!this.initialized)
            {
                this.initialized = true;
                this.InitializeComponent();
            }

            switch (propertyName)
            {
            case nameof(LabelText):
                lblLabel.Text      = LabelText;
                lblLabel.IsVisible = !string.IsNullOrEmpty(LabelText);
                break;

            case nameof(LabelTextColor):
                lblLabel.TextColor = LabelTextColor;
                break;

            case nameof(DisabledLabelTextColor):
                if (IsEnabled)
                {
                    lblLabel.TextColor = LabelTextColor;
                }
                else
                {
                    lblLabel.TextColor = DisabledLabelTextColor;
                }
                break;

            case nameof(LabelSize):
                lblLabel.FontSize = LabelSize;
                break;

            case nameof(LabelValueFormat):
                lblValue.Text = Value.ToString(LabelValueFormat);
                break;

            case nameof(LabelValueColor):
                lblValue.TextColor = LabelValueColor;
                break;

            case nameof(DisabledLabelValueColor):
                lblValue.TextColor = IsEnabled ? LabelValueColor : DisabledLabelValueColor;
                break;

            case nameof(LabelValueSize):
                lblValue.FontSize = LabelValueSize;
                break;

            case nameof(LabelValueIsVisible):
                lblValue.IsVisible = LabelValueIsVisible;
                lblValue.Text      = Value.ToString(LabelValueFormat);
                break;

            case nameof(LabelMinimumText):
                lblMinimum.Text      = LabelMinimumText;
                lblMinimum.IsVisible = !string.IsNullOrEmpty(LabelMinimumText) && (!ShowIcons || !MinimumIconIsVisible);
                break;

            case nameof(LabelMinimumTextColor):
                lblMinimum.TextColor = LabelMinimumTextColor;
                break;

            case nameof(DisabledLabelMinimumTextColor):
                if (IsEnabled)
                {
                    lblMinimum.TextColor = LabelMinimumTextColor;
                }
                else
                {
                    lblMinimum.TextColor = DisabledLabelMinimumTextColor;
                }
                break;

            case nameof(LabelMinimumSize):
                lblMinimum.FontSize = LabelMinimumSize;
                break;

            case nameof(LabelMaximumText):
                lblMaximum.Text      = LabelMaximumText;
                lblMaximum.IsVisible = !string.IsNullOrEmpty(LabelMaximumText) && (!ShowIcons || !MaximumIconIsVisible);
                break;

            case nameof(LabelMaximumTextColor):
                lblMaximum.TextColor = LabelMaximumTextColor;
                break;

            case nameof(DisabledLabelMaximumTextColor):
                if (IsEnabled)
                {
                    lblMaximum.TextColor = LabelMaximumTextColor;
                }
                else
                {
                    lblMaximum.TextColor = DisabledLabelMaximumTextColor;
                }
                break;

            case nameof(LabelMaximumSize):
                lblMaximum.FontSize = LabelMaximumSize;
                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(MinimumIcon):
                if (!string.IsNullOrEmpty(this.MinimumIcon))
                {
                    imgMinimum.SetImage(MinimumIcon);
                }

                SetMinimumIconIsVisible();
                break;

            case nameof(CustomMinimumIcon):
                if (CustomMinimumIcon != null)
                {
                    imgMinimum.SetCustomImage(CustomMinimumIcon);
                }

                SetMinimumIconIsVisible();
                break;

            case nameof(MaximumIcon):
                if (!string.IsNullOrEmpty(this.MaximumIcon))
                {
                    imgMaximum.SetImage(MaximumIcon);
                }

                SetMaximumIconIsVisible();
                break;

            case nameof(CustomMaximumIcon):
                if (CustomMaximumIcon != null)
                {
                    imgMaximum.SetCustomImage(CustomMaximumIcon);
                }

                SetMaximumIconIsVisible();
                break;

            case nameof(BackgroundImage):
                if (!string.IsNullOrEmpty(this.BackgroundImage))
                {
                    bckgImage.SetImage(BackgroundImage);
                    bckgImage.IsVisible = true;
                }
                else
                {
                    bckgImage.IsVisible = false;
                }

                break;

            case nameof(CustomBackgroundImage):
                if (CustomBackgroundImage != null)
                {
                    bckgImage.SetCustomImage(CustomBackgroundImage);
                    bckgImage.IsVisible = true;
                }
                else
                {
                    bckgImage.IsVisible = false;
                }

                break;

            case nameof(ThumbImage):
                if (!string.IsNullOrEmpty(this.ThumbImage))
                {
                    slider.ThumbImageSource = ThumbImage;
                }
                break;

            case nameof(MinimumValue):
                slider.Minimum = MinimumValue;
                break;

            case nameof(MaximumValue):
                slider.Maximum = MaximumValue;
                break;

            case nameof(ActiveTrackColor):
                slider.ActiveTrackColor = ActiveTrackColor;
                break;

            case nameof(InactiveTrackColor):
                slider.InactiveTrackColor = InactiveTrackColor;
                break;

            case nameof(ThumbColor):
                slider.ThumbColor = ThumbColor;
                break;

            case nameof(TrackHeight):
                slider.TrackHeight = TrackHeight;
                break;

            case nameof(TrackCornerRadius):
                slider.TrackCornerRadius = TrackCornerRadius;
                break;

            case nameof(UserInteractionEnabled):
                slider.UserInteractionEnabled = UserInteractionEnabled;
                break;

            case nameof(IsEnabled):
                this.IsEnabled = IsEnabled;
                SetEnable();
                break;

            case nameof(ShowIcons):
                SetMinimumIconIsVisible();
                SetMaximumIconIsVisible();
                break;
            }

            base.OnPropertyChanged(propertyName);
        }
        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (!this.initialized)
            {
                this.initialized = true;
                this.InitializeComponent();
            }

            switch (propertyName)
            {
            case nameof(base.TranslationX):
                base.OnPropertyChanged(propertyName);
                break;

            case nameof(this.IsEnabled):
                SetIsEnabled();
                break;

            case nameof(this.TextColor):
                SetTextColor();
                break;

            case nameof(this.FontSize):
                SetFontSize();
                break;

            case nameof(this.FontFamily):
                SetFontFamily();
                break;

            case nameof(this.Keyboard):
                this.txtEntry.Keyboard = this.Keyboard;
                break;

            case nameof(this.Length):
                this.txtEntry.MaxLength = this.Length;
                break;

            case nameof(this.LabelText):
                this.lblLabel.Text      = this.LabelText;
                this.lblLabel.IsVisible = !string.IsNullOrEmpty(this.LabelText);
                break;

            case nameof(this.LabelTextColor):
                SetLabelTextColor(lblLabel);
                break;

            case nameof(this.LabelSize):
                this.lblLabel.FontSize = this.LabelSize;
                break;

            case nameof(this.Padding):
                this.grdContainer.Padding = this.Padding;
                break;

            case nameof(CornerRadius):
                if (frmContainers != null)
                {
                    foreach (var frmContainer in frmContainers)
                    {
                        frmContainer.CornerRadius = Convert.ToInt32(CornerRadius);
                    }
                }
                break;

            case nameof(this.Type):
            case nameof(this.BackgroundColor):
            case nameof(this.BorderColor):
                SetTypeBackgroundAndBorderColor();
                break;

            case nameof(this.AssistiveText):
                this.lblAssistive.Text      = this.AssistiveText;
                this.lblAssistive.IsVisible = !string.IsNullOrEmpty(this.AssistiveText);
                if (this.AnimateError && !string.IsNullOrEmpty(this.AssistiveText))
                {
                    ShakeAnimation.Animate(this);
                }
                break;

            case nameof(this.AssistiveTextColor):
                this.lblAssistive.TextColor = this.AssistiveTextColor;
                break;

            case nameof(this.AssistiveSize):
                this.lblAssistive.FontSize = this.AssistiveSize;
                break;

            case nameof(this.TabIndex):
                if (this.TabIndex != 0)
                {
                    this.txtEntry.TabIndex = this.TabIndex;
                    this.TabIndex          = 0;
                }
                break;

            case nameof(this.IsTabStop):
                this.txtEntry.IsTabStop = this.IsTabStop;
                break;

            case nameof(this.ReturnType):
                this.txtEntry.ReturnType = this.ReturnType;

                if (this.ReturnType.Equals(Xamarin.Forms.ReturnType.Next))
                {
                    this.txtEntry.ReturnCommand = new Command(() =>
                    {
                        var currentTabIndex = this.txtEntry.TabIndex;
                        this.FocusNextElement(currentTabIndex);
                    });
                }
                break;

            case nameof(this.FieldHeightRequest):
                grdContainer.RowDefinitions = new RowDefinitionCollection();
                grdContainer.RowDefinitions.Add(new RowDefinition {
                    Height = this.FieldHeightRequest
                });

                if (frmContainers != null)
                {
                    foreach (var frmContainer in frmContainers)
                    {
                        frmContainer.HeightRequest = this.FieldHeightRequest;
                    }
                }
                break;

            case nameof(this.FieldWidthRequest):
                if (frmContainers != null)
                {
                    foreach (var frmContainer in frmContainers)
                    {
                        frmContainer.HorizontalOptions = LayoutOptions.Center;
                        frmContainer.WidthRequest      = this.FieldWidthRequest;
                    }
                }
                break;

            case nameof(this.IsCode):
                this.txtEntry.IsCode = this.IsCode;
                break;

            case nameof(HorizontalTextAlignment):
                SetHorizontalTextAlignment();
                break;
            }
        }
        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (!this.initialized)
            {
                this.InitializeComponent();
                this.initialized = true;
            }

            switch (propertyName)
            {
            case nameof(base.TranslationX):
                base.OnPropertyChanged(propertyName);
                break;

            case nameof(this.IsEnabled):
                this.pckOptions.IsEnabled = this.IsEnabled;
                break;

            case nameof(this.TextColor):
                this.pckOptions.TextColor = this.TextColor;
                break;

            case nameof(this.FontSize):
                this.pckOptions.FontSize = this.FontSize;
                break;

            case nameof(this.LabelText):
                this.lblLabel.Text      = this.LabelText;
                this.lblLabel.IsVisible = !string.IsNullOrEmpty(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.Padding):
                this.frmContainer.Padding = this.Padding;
                break;

            case nameof(this.Type):
            case nameof(this.BackgroundColor):
            case nameof(this.BorderColor):
                switch (this.Type)
                {
                case FieldTypes.Filled:
                    this.frmContainer.BackgroundColor = this.BackgroundColor;
                    this.frmContainer.BorderColor     = this.BorderColor;
                    this.frmContainer.CornerRadius    = 20;
                    this.bxvLine.IsVisible            = false;
                    break;

                case FieldTypes.Outlined:
                    this.frmContainer.BackgroundColor = this.BackgroundColor;
                    this.frmContainer.BorderColor     = this.BorderColor;
                    this.frmContainer.CornerRadius    = 4;
                    this.bxvLine.IsVisible            = false;
                    break;

                case FieldTypes.Lined:
                    this.frmContainer.BackgroundColor = Color.Transparent;
                    this.frmContainer.BorderColor     = Color.Transparent;
                    this.bxvLine.IsVisible            = true;
                    this.bxvLine.Color = this.BorderColor;

                    this.frmContainer.HeightRequest = 30;

                    if (this.LeadingIconIsVisible)
                    {
                        this.lblLabel.Margin = new Thickness(36, this.lblLabel.Margin.Top,
                                                             this.lblLabel.Margin.Right, 0);
                        this.frmContainer.Padding = new Thickness(0);
                        this.lblAssistive.Margin  = new Thickness(36, this.lblAssistive.Margin.Top,
                                                                  this.lblAssistive.Margin.Right, this.lblAssistive.Margin.Bottom);
                        this.bxvLine.Margin = new Thickness(36, 0, 0, 0);
                    }
                    else
                    {
                        this.lblLabel.Margin      = new Thickness(0, this.lblLabel.Margin.Top, 0, 0);
                        this.frmContainer.Padding = new Thickness(0);
                        this.lblAssistive.Margin  = new Thickness(0, this.lblAssistive.Margin.Top, 0, this.lblAssistive.Margin.Bottom);
                    }
                    break;
                }
                break;

            case nameof(this.AssistiveText):
                this.lblAssistive.Text      = this.AssistiveText;
                this.lblAssistive.IsVisible = !string.IsNullOrEmpty(this.AssistiveText);
                if (this.AnimateError && !string.IsNullOrEmpty(this.AssistiveText))
                {
                    ShakeAnimation.Animate(this);
                }
                break;

            case nameof(this.AssistiveTextColor):
                this.lblAssistive.TextColor = this.AssistiveTextColor;
                break;

            case nameof(this.AssistiveSize):
                this.lblAssistive.FontSize = this.AssistiveSize;
                break;

            case nameof(this.LeadingIcon):
                if (!string.IsNullOrEmpty(this.LeadingIcon))
                {
                    this.imgLeadingIcon.Image.Source = this.LeadingIcon;
                }
                this.imgLeadingIcon.IsVisible = this.LeadingIconIsVisible;
                break;

            case nameof(this.TrailingIcon):
                if (!string.IsNullOrEmpty(this.TrailingIcon))
                {
                    this.imgTrailingIcon.Image.Source = this.TrailingIcon;
                }
                this.imgTrailingIcon.IsVisible = this.TrailingIconIsVisible && this.IsEnabled;
                break;
            }
        }
Beispiel #7
0
        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (!this.initialized)
            {
                this.initialized = true;
                this.InitializeComponent();
            }

            switch (propertyName)
            {
            case nameof(base.TranslationX):
                base.OnPropertyChanged(propertyName);
                break;

            case nameof(this.IsEnabled):
                SetIsEnabled();
                break;

            case nameof(this.TextColor):
                SetTextColor();
                break;

            case nameof(this.FontSize):
                SetFontSize();
                break;

            case nameof(this.FontFamily):
                SetFontFamily();
                break;

            case nameof(this.Keyboard):
                this.txtEntry.Keyboard = this.Keyboard;
                break;

            case nameof(KeyboardFlags):
                if (KeyboardFlags != null)
                {
                    try
                    {
                        string[]      flagNames = ((string)KeyboardFlags).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        KeyboardFlags allFlags  = 0;
                        foreach (var flagName in flagNames)
                        {
                            KeyboardFlags flags = 0;
                            Enum.TryParse <KeyboardFlags>(flagName.Trim(), out flags);
                            if (flags != 0)
                            {
                                allFlags |= flags;
                            }
                        }
                        txtEntry.Keyboard = Keyboard.Create(allFlags);
                    }
                    catch
                    {
                        throw new XamlParseException("The keyboard flags are invalid or have a wrong specification.");
                    }
                }
                break;

            case nameof(TextTransform):
                ApplyTextTransform();
                break;

            case nameof(this.Length):
                this.txtEntry.MaxLength = this.Length;
                break;

            case nameof(this.LabelText):
                this.lblLabel.Text      = this.LabelText;
                this.lblLabel.IsVisible = !string.IsNullOrEmpty(this.LabelText);
                break;

            case nameof(this.LabelTextColor):
                SetLabelTextColor(lblLabel);
                break;

            case nameof(this.LabelSize):
                this.lblLabel.FontSize = this.LabelSize;
                break;

            case nameof(this.Padding):
                this.grdContainer.Padding = this.Padding;
                break;

            case nameof(CornerRadius):
                if (frmContainers != null)
                {
                    foreach (var frmContainer in frmContainers)
                    {
                        frmContainer.CornerRadius = Convert.ToInt32(CornerRadius);
                    }
                }
                break;

            case nameof(this.Type):
            case nameof(this.BackgroundColor):
            case nameof(this.BorderColor):
                SetTypeBackgroundAndBorderColor();
                break;

            case nameof(this.AssistiveText):
                this.lblAssistive.Text      = this.AssistiveText;
                this.lblAssistive.IsVisible = !string.IsNullOrEmpty(this.AssistiveText);
                if (this.AnimateError && !string.IsNullOrEmpty(this.AssistiveText))
                {
                    ShakeAnimation.Animate(this);
                }
                break;

            case nameof(this.AssistiveTextColor):
                this.lblAssistive.TextColor = this.AssistiveTextColor;
                break;

            case nameof(this.AssistiveSize):
                this.lblAssistive.FontSize = this.AssistiveSize;
                break;

            case nameof(this.TabIndex):
                if (this.TabIndex != 0)
                {
                    this.txtEntry.TabIndex = this.TabIndex;
                    this.TabIndex          = 0;
                }
                break;

            case nameof(this.IsTabStop):
                this.txtEntry.IsTabStop = this.IsTabStop;
                break;

            case nameof(this.ReturnType):
                this.txtEntry.ReturnType = this.ReturnType;

                if (this.ReturnType.Equals(Xamarin.Forms.ReturnType.Next))
                {
                    this.txtEntry.ReturnCommand = new Command(() =>
                    {
                        var currentTabIndex = this.txtEntry.TabIndex;
                        this.FocusNextElement(currentTabIndex);
                    });
                }
                break;

            case nameof(this.FieldHeightRequest):
                grdContainer.RowDefinitions = new RowDefinitionCollection();
                grdContainer.RowDefinitions.Add(new RowDefinition {
                    Height = this.FieldHeightRequest
                });

                if (frmContainers != null)
                {
                    foreach (var frmContainer in frmContainers)
                    {
                        frmContainer.HeightRequest = this.FieldHeightRequest;
                    }
                }
                break;

            case nameof(this.FieldWidthRequest):
                if (frmContainers != null)
                {
                    foreach (var frmContainer in frmContainers)
                    {
                        frmContainer.HorizontalOptions = LayoutOptions.Center;
                        frmContainer.WidthRequest      = this.FieldWidthRequest;
                    }
                }
                break;

            case nameof(this.IsCode):
                this.txtEntry.IsCode = this.IsCode;
                break;

            case nameof(HorizontalTextAlignment):
                SetHorizontalTextAlignment();
                break;
            }
        }
Beispiel #8
0
        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (!this.initialized)
            {
                this.InitializeComponent();
                this.initialized = true;
            }

            // TODO: Check if you can take out the strong password.

            switch (propertyName)
            {
            case nameof(base.TranslationX):
                base.OnPropertyChanged(propertyName);
                break;

            case nameof(this.IsEnabled):
                this.txtEntry.IsEnabled = this.IsEnabled;
                break;

            case nameof(this.TextColor):
                this.txtEntry.TextColor = this.TextColor;
                break;

            case nameof(this.FontSize):
                this.txtEntry.FontSize = this.FontSize;
                break;

            case nameof(this.FontFamily):
                this.txtEntry.FontFamily     = this.FontFamily;
                this.lblLabel.FontFamily     = this.FontFamily;
                this.lblAssistive.FontFamily = this.FontFamily;
                break;

            case nameof(this.Placeholder):
                this.txtEntry.Placeholder = this.Placeholder;
                break;

            case nameof(this.PlaceholderColor):
                this.txtEntry.PlaceholderColor = this.PlaceholderColor;
                break;

            case nameof(this.Keyboard):
                this.txtEntry.Keyboard = this.Keyboard;
                break;

            case nameof(this.MaxLength):
                this.txtEntry.MaxLength = this.MaxLength;
                break;

            case nameof(this.LabelText):
                this.lblLabel.Text      = this.LabelText;
                this.lblLabel.IsVisible = !string.IsNullOrEmpty(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.Padding):
                this.frmContainer.Padding = this.Padding;
                break;

            case nameof(this.Type):
            case nameof(this.BackgroundColor):
            case nameof(this.BorderColor):
                switch (this.Type)
                {
                case FieldTypes.Filled:
                    this.frmContainer.BackgroundColor = this.BackgroundColor;
                    this.frmContainer.BorderColor     = this.BorderColor;
                    this.frmContainer.CornerRadius    = 20;
                    this.bxvLine.IsVisible            = false;
                    break;

                case FieldTypes.Outlined:
                    this.frmContainer.BackgroundColor = this.BackgroundColor;
                    this.frmContainer.BorderColor     = this.BorderColor;
                    this.frmContainer.CornerRadius    = 4;
                    this.bxvLine.IsVisible            = false;
                    break;

                case FieldTypes.Lined:
                    this.frmContainer.BackgroundColor = Color.Transparent;
                    this.frmContainer.BorderColor     = Color.Transparent;
                    this.bxvLine.IsVisible            = true;
                    this.bxvLine.Color = this.BorderColor;

                    this.frmContainer.HeightRequest = 30;

                    if (this.LeadingIconIsVisible)
                    {
                        this.lblLabel.Margin = new Thickness(36, this.lblLabel.Margin.Top,
                                                             this.lblLabel.Margin.Right, 0);
                        this.frmContainer.Padding = new Thickness(0);
                        this.lblAssistive.Margin  = new Thickness(36, this.lblAssistive.Margin.Top,
                                                                  this.lblAssistive.Margin.Right, this.lblAssistive.Margin.Bottom);
                        this.bxvLine.Margin = new Thickness(36, 0, 0, 0);
                    }
                    else
                    {
                        this.lblLabel.Margin      = new Thickness(0, this.lblLabel.Margin.Top, 0, 0);
                        this.frmContainer.Padding = new Thickness(0);
                        this.lblAssistive.Margin  = new Thickness(0, this.lblAssistive.Margin.Top, 0, this.lblAssistive.Margin.Bottom);
                    }
                    break;
                }
                break;

            case nameof(this.AssistiveText):
                this.lblAssistive.Text      = this.AssistiveText;
                this.lblAssistive.IsVisible = !string.IsNullOrEmpty(this.AssistiveText);
                if (this.AnimateError && !string.IsNullOrEmpty(this.AssistiveText))
                {
                    ShakeAnimation.Animate(this);
                }
                break;

            case nameof(this.AssistiveTextColor):
                this.lblAssistive.TextColor = this.AssistiveTextColor;
                break;

            case nameof(this.AssistiveSize):
                this.lblAssistive.FontSize = this.AssistiveSize;
                break;

            case nameof(this.IsPassword):
            case nameof(this.ShowPasswordIcon):
            case nameof(this.ShowPasswordIconIsVisible):
                this.txtEntry.IsPassword = this.IsPassword;
                if (!string.IsNullOrEmpty(this.ShowPasswordIcon))
                {
                    this.imgShowPasswordIcon.Image.Source = this.ShowPasswordIcon;
                }
                this.imgShowPasswordIcon.IsVisible = this.IsPassword && this.ShowPasswordIconIsVisible && !string.IsNullOrEmpty(this.ShowPasswordIcon);
                break;

            case nameof(this.ClearIcon):
            case nameof(this.ClearIconIsVisible):
                if (!string.IsNullOrEmpty(this.ClearIcon))
                {
                    this.imgClearIcon.Image.Source = this.ClearIcon;
                }
                this.imgClearIcon.IsVisible = this.ClearIconIsVisible && this.IsEnabled && !string.IsNullOrEmpty(this.Text);
                break;

            case nameof(this.LeadingIcon):
                if (!string.IsNullOrEmpty(this.LeadingIcon))
                {
                    this.imgLeadingIcon.Image.Source = this.LeadingIcon;
                }
                this.imgLeadingIcon.IsVisible = this.LeadingIconIsVisible;
                break;

            case nameof(this.TrailingIcon):
                if (!string.IsNullOrEmpty(this.TrailingIcon))
                {
                    this.imgTrailingIcon.Image.Source = this.TrailingIcon;
                }
                this.imgTrailingIcon.IsVisible = this.TrailingIconIsVisible;
                break;

            case nameof(this.TabIndex):
                if (this.TabIndex != 0)
                {
                    this.txtEntry.TabIndex = this.TabIndex;
                    this.TabIndex          = 0;
                }
                break;

            case nameof(this.IsTabStop):
                this.txtEntry.IsTabStop = this.IsTabStop;
                break;

            case nameof(this.ReturnType):
                this.txtEntry.ReturnType = this.ReturnType;

                if (this.ReturnType.Equals(Xamarin.Forms.ReturnType.Next))
                {
                    this.txtEntry.ReturnCommand = new Command(() =>
                    {
                        var currentTabIndex = this.txtEntry.TabIndex;
                        this.FocusNextElement(currentTabIndex);
                    });
                }
                break;
            }
        }
Beispiel #9
0
        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (!this.initialized)
            {
                this.initialized = true;
                this.InitializeComponent();


                // TODO: add autosize property
                this.txtEditor.AutoSize = EditorAutoSizeOption.Disabled;

                // TODO: apply the height of the control.
            }

            switch (propertyName)
            {
            case nameof(base.TranslationX):
                base.OnPropertyChanged(propertyName);
                break;

            case nameof(this.IsEnabled):
                this.txtEditor.IsEnabled = this.IsEnabled;
                break;

            case nameof(this.TextColor):
                this.txtEditor.TextColor = this.TextColor;
                break;

            case nameof(this.FontSize):
                this.txtEditor.FontSize = this.FontSize;
                break;

            case nameof(this.FontFamily):
                this.txtEditor.FontFamily    = this.FontFamily;
                this.lblLabel.FontFamily     = this.FontFamily;
                this.lblAssistive.FontFamily = this.FontFamily;
                break;

            case nameof(this.Placeholder):
                this.txtEditor.Placeholder = this.Placeholder;
                break;

            case nameof(this.PlaceholderColor):
                this.txtEditor.PlaceholderColor = this.PlaceholderColor;
                break;

            case nameof(this.Keyboard):
                this.txtEditor.Keyboard = this.Keyboard;
                break;

            case nameof(this.MaxLength):
                this.txtEditor.MaxLength = this.MaxLength;
                break;

            case nameof(this.LabelText):
                this.lblLabel.Text      = this.LabelText;
                this.lblLabel.IsVisible = !string.IsNullOrEmpty(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.Padding):
                this.frmContainer.Padding = this.Padding;
                break;

            case nameof(this.Type):
            case nameof(this.BackgroundColor):
            case nameof(this.BorderColor):
                switch (this.Type)
                {
                case FieldTypes.Filled:
                    this.frmContainer.BackgroundColor = this.BackgroundColor;
                    this.frmContainer.BorderColor     = this.BorderColor;
                    this.frmContainer.CornerRadius    = 20;
                    this.bxvLine.IsVisible            = false;
                    break;

                case FieldTypes.Outlined:
                    this.frmContainer.BackgroundColor = this.BackgroundColor;
                    this.frmContainer.BorderColor     = this.BorderColor;
                    this.frmContainer.CornerRadius    = 4;
                    this.bxvLine.IsVisible            = false;
                    break;

                case FieldTypes.Lined:
                    this.frmContainer.BackgroundColor = Color.Transparent;
                    this.frmContainer.BorderColor     = Color.Transparent;
                    this.bxvLine.IsVisible            = true;
                    this.bxvLine.Color = this.BorderColor;

                    //this.frmContainer.HeightRequest = 30;

                    if (this.LeadingIconIsVisible)
                    {
                        this.lblLabel.Margin = new Thickness(36, this.lblLabel.Margin.Top,
                                                             this.lblLabel.Margin.Right, 0);
                        this.frmContainer.Padding = new Thickness(0);
                        this.lblAssistive.Margin  = new Thickness(36, this.lblAssistive.Margin.Top,
                                                                  this.lblAssistive.Margin.Right, this.lblAssistive.Margin.Bottom);
                        this.bxvLine.Margin = new Thickness(36, 0, 0, 0);
                    }
                    else
                    {
                        this.lblLabel.Margin      = new Thickness(0, this.lblLabel.Margin.Top, 0, 0);
                        this.frmContainer.Padding = new Thickness(0);
                        this.lblAssistive.Margin  = new Thickness(0, this.lblAssistive.Margin.Top, 0, this.lblAssistive.Margin.Bottom);
                    }
                    break;
                }
                break;

            case nameof(this.AssistiveText):
                this.lblAssistive.Text      = this.AssistiveText;
                this.lblAssistive.IsVisible = !string.IsNullOrEmpty(this.AssistiveText);
                if (this.AnimateError && !string.IsNullOrEmpty(this.AssistiveText))
                {
                    ShakeAnimation.Animate(this);
                }
                break;

            case nameof(this.AssistiveTextColor):
                this.lblAssistive.TextColor = this.AssistiveTextColor;
                break;

            case nameof(this.AssistiveSize):
                this.lblAssistive.FontSize = this.AssistiveSize;
                break;

            case nameof(this.ClearIcon):
            case nameof(this.ClearIconIsVisible):
                if (!string.IsNullOrEmpty(this.ClearIcon))
                {
                    this.imgClearIcon.Image.Source = this.ClearIcon;
                }
                this.imgClearIcon.IsVisible = this.ClearIconIsVisible && this.IsEnabled && !string.IsNullOrEmpty(this.Text);
                break;

            case nameof(this.LeadingIcon):
                if (!string.IsNullOrEmpty(this.LeadingIcon))
                {
                    this.imgLeadingIcon.Image.Source = this.LeadingIcon;
                }
                this.imgLeadingIcon.IsVisible = this.LeadingIconIsVisible;
                break;

            case nameof(this.TrailingIcon):
                if (!string.IsNullOrEmpty(this.TrailingIcon))
                {
                    this.imgTrailingIcon.Image.Source = this.TrailingIcon;
                }
                this.imgTrailingIcon.IsVisible = this.TrailingIconIsVisible;
                break;

            case nameof(this.TabIndex):
                if (this.TabIndex != 0)
                {
                    this.txtEditor.TabIndex = this.TabIndex;
                    this.TabIndex           = 0;
                }
                break;

            case nameof(this.IsTabStop):
                this.txtEditor.IsTabStop = this.IsTabStop;
                break;

            case nameof(this.FieldHeightRequest):
                this.frmContainer.HeightRequest = this.FieldHeightRequest;
                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;
            }
        }
Beispiel #11
0
        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (!this.initialized)
            {
                try
                {
                    this.InitializeComponent();
                    this.initialized = true;
                }
                catch (Exception e)
                {
                    //HACK: When run using XF 4.4 there are a bunch of NameScope errors, not sure why
                    Debug.WriteLine("MediaDoublePicker.xaml.xs  : " + e.Message + " : Property - " + propertyName);
                }
            }

            switch (propertyName)
            {
            case nameof(base.TranslationX):
                base.OnPropertyChanged(propertyName);
                break;

            case nameof(this.IsEnabled):
                this.pckOptions.IsEnabled = this.IsEnabled;
                break;

            case nameof(this.TextColor):
                this.pckOptions.TextColor = this.TextColor;
                break;

            case nameof(this.FontSize):
                this.pckOptions.FontSize = this.FontSize;
                break;

            case nameof(this.FontFamily):
                this.pckOptions.FontFamily   = this.FontFamily;
                this.lblLabel.FontFamily     = this.FontFamily;
                this.lblAssistive.FontFamily = this.FontFamily;
                break;

            case nameof(this.LabelText):
                this.lblLabel.Text      = this.LabelText;
                this.lblLabel.IsVisible = !string.IsNullOrEmpty(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.Padding):
                this.frmContainer.Padding = this.Padding;
                break;

            case nameof(this.Type):
            case nameof(this.BackgroundColor):
            case nameof(this.BorderColor):
                switch (this.Type)
                {
                case FieldTypes.Filled:
                    this.frmContainer.BackgroundColor = this.BackgroundColor;
                    this.frmContainer.BorderColor     = this.BorderColor;
                    this.frmContainer.CornerRadius    = 20;
                    this.bxvLine.IsVisible            = false;
                    break;

                case FieldTypes.Outlined:
                    this.frmContainer.BackgroundColor = this.BackgroundColor;
                    this.frmContainer.BorderColor     = this.BorderColor;
                    this.frmContainer.CornerRadius    = 4;
                    this.bxvLine.IsVisible            = false;
                    break;

                case FieldTypes.Lined:
                    this.frmContainer.BackgroundColor = Color.Transparent;
                    this.frmContainer.BorderColor     = Color.Transparent;
                    this.bxvLine.IsVisible            = true;
                    this.bxvLine.Color = this.BorderColor;

                    this.frmContainer.HeightRequest = 30;

                    if (this.LeadingIconIsVisible)
                    {
                        this.lblLabel.Margin = new Thickness(36, this.lblLabel.Margin.Top,
                                                             this.lblLabel.Margin.Right, 0);
                        this.frmContainer.Padding = new Thickness(0);
                        this.lblAssistive.Margin  = new Thickness(36, this.lblAssistive.Margin.Top,
                                                                  this.lblAssistive.Margin.Right, this.lblAssistive.Margin.Bottom);
                        this.bxvLine.Margin = new Thickness(36, 0, 0, 0);
                    }
                    else
                    {
                        this.lblLabel.Margin      = new Thickness(0, this.lblLabel.Margin.Top, 0, 0);
                        this.frmContainer.Padding = new Thickness(0);
                        this.lblAssistive.Margin  = new Thickness(0, this.lblAssistive.Margin.Top, 0, this.lblAssistive.Margin.Bottom);
                    }
                    break;
                }
                break;

            case nameof(this.AssistiveText):
                this.lblAssistive.Text      = this.AssistiveText;
                this.lblAssistive.IsVisible = !string.IsNullOrEmpty(this.AssistiveText);
                if (this.AnimateError && !string.IsNullOrEmpty(this.AssistiveText))
                {
                    ShakeAnimation.Animate(this);
                }
                break;

            case nameof(this.AssistiveTextColor):
                this.lblAssistive.TextColor = this.AssistiveTextColor;
                break;

            case nameof(this.AssistiveSize):
                this.lblAssistive.FontSize = this.AssistiveSize;
                break;

            case nameof(this.LeadingIcon):
                if (!string.IsNullOrEmpty(this.LeadingIcon))
                {
                    this.imgLeadingIcon.Image.Source = this.LeadingIcon;
                }
                this.imgLeadingIcon.IsVisible = this.LeadingIconIsVisible;
                break;

            case nameof(this.TrailingIcon):
                if (!string.IsNullOrEmpty(this.TrailingIcon))
                {
                    this.imgTrailingIcon.Image.Source = this.TrailingIcon;
                }
                this.imgTrailingIcon.IsVisible = this.TrailingIconIsVisible && this.IsEnabled;
                break;

            case nameof(this.HorizontalTextAlignment):
                this.lblLabel.HorizontalTextAlignment     = this.HorizontalTextAlignment;
                this.pckOptions.HorizontalTextAlignment   = this.HorizontalTextAlignment;
                this.lblAssistive.HorizontalTextAlignment = this.HorizontalTextAlignment;
                break;

            case nameof(this.Placeholder):
                this.pckOptions.Placeholder = this.Placeholder;
                break;

            case nameof(this.PlaceholderColor):
                this.pckOptions.PlaceholderColor = this.PlaceholderColor;
                break;

            case nameof(this.Separator):
                this.pckOptions.Separator = this.Separator;
                break;
            }
        }