Effect on Entry

Manickam, Suraj 320 Reputation points
2023-12-07T12:56:07.01+00:00

I am trying to add an effect on Entry ,when onComplete it has to focus on next Entry . But somehow it does not trigger the effect

I created this according to the doc

    internal class EntryMoveNextEffect : RoutingEffect{
    
    }
#if ANDROID
    internal class EntryPlatformEffect  :PlatformEffect
    {
        protected override void OnAttached()
        {
            // Check if the attached element is of the expected type and has the NextEntry
            // property set. if so, configure the keyboard to indicate there is another entry
            // in the form and the dismiss action to focus on the next entry
            if (base.Element is EntryMoveNextControl xfControl && xfControl.NextEntry != null)
            {

                var entry = (Android.Widget.EditText)Control;
                entry.ImeOptions = Android.Views.InputMethods.ImeAction.Next;
                entry.EditorAction += (sender, args) =>
                {
                    xfControl.OnNext();

                };
            }
        }

        protected override void OnElementPropertyChanged(PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "IsFocused")
            {
                var entry = (Android.Widget.EditText)Control;
                entry.SetSelectAllOnFocus(true);
            }
        }
        protected override void OnDetached()
        {
            // Intentionally empty
        }
    }
#elif IOS
    internal class EntryPlatformEffect : PlatformEffect
    {
        protected override void OnAttached()
        {
            // Customize the control here
        }

        protected override void OnDetached()
        {
            // Cleanup the control customization here
        }
    }
#elif WINDOWS
    internal class EntryPlatformEffect : PlatformEffect
    {
        protected override void OnAttached()
        {
            // Customize the control here
        }

        protected override void OnDetached()
        {
            // Cleanup the control customization here
        }
    }
#endif

added this in builder file.cs

   .ConfigureEffects(effects =>    {        effects.Add<EntryMoveNextEffect,EntryPlatformEffect>();    });

and to consume this

<Entry>
  <Entry.Effects>          
		<customControl:EntryMoveNextEffect />   
  </Entry.Effects>
</Entry>

but it does not seem to work !
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,834 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 78,671 Reputation points Microsoft Vendor
    2023-12-14T05:21:59.2866667+00:00

    Hello,

    When you use this custom entry, you need to set x:name for your previous EntryMoveNextControl, then set NextEntry="{x:Reference yourPreviousEntry}" for your next EntryMoveNextControl`.

    For example, if you have two <EntryMoveNextControl> contros in your xaml layout, the first one set the x:Name that called x:Name="myFirstEntry", you can set NextEntry="{x:Reference myFirstEntry}" for your second <EntryMoveNextControl> like following code.

    <ContentPage 
    ...
                 xmlns:local="clr-namespace:yourproject"
    ...
    >
    
    <local:EntryMoveNextControl x:Name="myFirstEntry"  >
    
    
         <local:EntryMoveNextControl.Effects>
             <local:EntryMoveNextEffect></local:EntryMoveNextEffect>
         </local:EntryMoveNextControl.Effects>
    
    </local:EntryMoveNextControl>
    
    
     <local:EntryMoveNextControl  x:Name="myentry"  NextEntry="{x:Reference myFirstEntry}">
         <local:EntryMoveNextControl.Effects>
             <local:EntryMoveNextEffect></local:EntryMoveNextEffect>
         </local:EntryMoveNextControl.Effects>
    
    </local:EntryMoveNextControl>
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.