Skip to content

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

@jaladaGmbH

Description

@jaladaGmbH

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions