0
votes

This seems to be behavior in Entry also. But we can change this behavior in Entry using Effects (https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/effects/). We have tried CustomView but the entire behavior is changed In Xamarin.Forms UWP does not update the background color in focused state. In this, I have created “NumericTextBox” which is inherit from TextBox in UWP. And I have created a “NumericTextBox_Forms” inherits from View in XForms. In UWP Renderer class create a new instance for “NumericTextBox” and set native control. And please find my sample below.

<StackLayout Padding="0,20,0,0">
        <Entry Keyboard="Numeric">
            <Entry.Effects>
                <local:FocusEffect/>
            </Entry.Effects>
            <Entry.Triggers>
                <Trigger TargetType="Entry" Property="IsFocused" Value="True">
                    <Setter Property="BackgroundColor" Value="Yellow" />
                </Trigger>
            </Entry.Triggers>
        </Entry>
        <NumericTextBox_Forms>
            <NumericTextBox_Forms.Effects>
                <local:FocusEffect/>
            </NumericTextBox_Forms.Effects>
            <NumericTextBox_Forms.Triggers>
                <Trigger TargetType="sync:SfMaskedEdit" Property="IsFocused" Value="True">
                    <Setter Property="BackgroundColor" Value="Blue" />
                </Trigger>
            </NumericTextBox_Forms.Triggers>
        </NumericTextBox_Forms >

    </StackLayout>

1

1 Answers

0
votes

BackgroundColor is not applied when the View is focused on UWP

For the testing SfMaskedEdit contains method internal override IsFocused trigger. For the scenario, I suggest make custom render for NumericTextBox_Forms then edit the bg color in control GettingFocus event.

[assembly: ExportRenderer(typeof(NumericTextBox_Forms), typeof(NumericTextBoxRender))]
namespace XamarinEffect.UWP
{
    public class NumericTextBoxRender :SfMaskedEditRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Syncfusion.XForms.MaskedEdit.SfMaskedEdit> e)
        {
            base.OnElementChanged(e);

            if(Control != null)
            {
                Control.GettingFocus += Control_GettingFocus;
            }
        }

        private void Control_GettingFocus(Windows.UI.Xaml.UIElement sender, Windows.UI.Xaml.Input.GettingFocusEventArgs args)
        {
            Control.Background = new SolidColorBrush(Colors.Blue);
        }
    }
}

I tried above, it works well in my side, hope could solve your problem.