当View聚焦于UWP时不应用BackgroundColor

问题描述 投票:0回答:1

这似乎也是Entry中的行为。但是我们可以使用效果(https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/effects/)在Entry中更改此行为。我们尝试了CustomView,但整个行为已更改在Xamarin.Forms中,UWP不会在聚焦状态下更新背景色。在此,我创建了“ NumericTextBox”,它是从UWP中的TextBox继承而来的。并且我创建了一个“ NumericTextBox_Forms”,它继承自XForms中的View。在UWP Renderer类中,为“ NumericTextBox”创建一个新实例并设置本机控件。并且请在下面找到我的示例。

<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>

c# xamarin xamarin.forms uwp xamarin.uwp
1个回答
0
投票

当视图集中在UWP上时,不应用BackgroundColor

对于测试,SfMaskedEdit包含方法内部重写IsFocused触发器。对于这种情况,我建议为NumericTextBox_Forms进行自定义渲染,然后在控件GettingFocus事件中编辑bg颜色。

[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);
        }
    }
}

我在上面尝试过,在我这方面效果很好,希望可以解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.