Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TagEntryView loses focus when a new tag is added on UWP. #292

Open
jaladaGmbH opened this issue Jun 21, 2020 · 0 comments
Open

TagEntryView loses focus when a new tag is added on UWP. #292

jaladaGmbH opened this issue Jun 21, 2020 · 0 comments

Comments

@jaladaGmbH
Copy link

On UWP a view loses its focus if it is removed from its parent view. In TagEntryView.ForceReload() you call in line 214 Children.Clear() which removes all child views from your control, including your Entry control.

To prevent your control from losing focus, you should only remove your tag views, not the entry from the layout. A solution could look like this:`

    public void ForceReload()
    {
        if (TagItems == null)
            return;

        List<View> list = Children.ToList();
        foreach (var view in list)
        {
            if (view != TagEntry)
            {
                Children.Remove(view);
            }
        }

        for (int i = 0; i < TagItems.Count; i++)
        {
            View view = null;

            if (TagItemTemplate is DataTemplateSelector templateSelector)
            {
                var template = templateSelector.SelectTemplate(TagItems[i], null);
                view = (View)template.CreateContent();
            }
            else
            {
                view = (View)TagItemTemplate.CreateContent();
            }

            view.BindingContext = TagItems[i];

            view.GestureRecognizers.Add(new TapGestureRecognizer()
            {
                Command = new Command(() => PerformTagTap(view.BindingContext))
            });

            Children.Insert(Children.Count - 1, view);
        }
    }

`
Best regards
Andreas | jalada GmbH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant