More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Friday, 29 March 2019 7:33:55 AM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 501

Xamarin forms Entry control with clear button by ClearEntryEffect

Xamarin forms Entry control doesn't have the clear future built-in. However, Depechie has provided a solution, see Xamarin forms – Clear entry control effect. You can also his source code in github. You just need to copy the Effects cs files into your shared, Android and iOS projects. You may need to change the namespace accordingly. FYI: fundamentals of creating effects on Xamarin forms

Please note that the effect not only works for Entry control but also Editor control, which is a multi-line text editor.

I followed Depechie's article. I got ClearEntryEffect working on Android. But I have the following issues with the feature on iOS:

PlatformEffect fails to attach to Page elements in iOS

cf https://bugzilla.xamarin.com/show_bug.cgi?id=40271

The issue should have been fixed long time ago.

I use Xamarin.forms 3.1.0.697729, but I still have the same problem.

For iOS, I have to add an EntryRenderer EntryWithClearButonRenderer in iOS project, and a derived Entry control EntryWithClearButon, which is placed in the Renders folder in shared project.

In this way I got it working. But this just a workaround because PlatformEffect doesn't call OnAttached in iOS even though I have the ClearEentryEffect in xaml of the page.

See my code below

Code:
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(EntryWithClearButon), typeof(EntryWithClearButonRenderer))]

namespace tecommobile.iOS
{
    public class EntryWithClearButonRenderer : EntryRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                Control.ClearButtonMode = UITextFieldViewMode.WhileEditing;
            }
        }
    }
}



Code:
    public class EntryWithClearButon : Entry
    {
        public EntryWithClearButon()
        {
        }

        public string EntryText { get; set; }
    }

Edited by user Friday, 29 March 2019 7:39:24 AM(UTC)  | Reason: Not specified

Sponsor
Rss Feed  Atom Feed
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.