ListView ListViewCachingStrategy.RecycleElement

csampaio01csampaio01 PTMember ✭✭✭

Hi, I need to set the ListView caching to recycle and it works. The problem is when I need to filter the results, the objects inside goes blank.

To filter I use:

txtPesquisa.TextChanged += (sender, e) => { lista.BeginRefresh(); lista.ItemsSource = ClientesBD.GetClientes(txtPesquisa.Text); lista.EndRefresh(); };

Answers

  • csampaio01csampaio01 PTMember ✭✭✭

    My Listview:

    ` lista = new MyListView(ListViewCachingStrategy.RecycleElement)
    {
    Margin = new Thickness(10),
    RowHeight = 60,
    ItemTemplate = new DataTemplate(typeof(ClienteCell))

        };`
    

    My Template:

    ` [Foundation.Preserve(AllMembers = true)]
    public class ClienteCell : ViewCell
    {
    protected override void OnBindingContextChanged()
    {
    base.OnBindingContextChanged();

        Cliente cliente = (Cliente)BindingContext;
    
        var label = new Label
        {
            VerticalTextAlignment = TextAlignment.Center,
            HorizontalTextAlignment = TextAlignment.Center,
            FontSize = 13,
    
            Style = (Style)Application.Current.Resources["labelNormal"]
        };
        label.SetBinding(Label.TextProperty, new Binding("nome"));
    
        View = label;
    }
    

    }`

  • seanydaseanyda GBMember ✭✭✭✭✭

    Have you tried filtering with System.Linq instead?

    lista.ItemsSource = ClientesBD.GetClientes.Where(w => w.nome.ToLower().Contains(txtPesquisa.Text.ToLower())).ToList();

    You would need the GetClientEs() method to return all results if null. Code isn't tested but should work.

  • csampaio01csampaio01 PTMember ✭✭✭

    @seanyda Thanks for your answer.

    It doesn't work anyway. Inside the method I am using Linq to filter the results.
    It filters, but the list view turns blank lines.

  • seanydaseanyda GBMember ✭✭✭✭✭

    @csampaio01 said:
    @seanyda Thanks for your answer.

    It doesn't work anyway. Inside the method I am using Linq to filter the results.
    It filters, but the list view turns blank lines.

    I use System.Linq to do all my filtering from a list, It's always worked perfectly. If you can show me all your code I might be able to fix it for you.

  • csampaio01csampaio01 PTMember ✭✭✭

    @seanyda Did you placed the caching strategy to recycle?

    here you go:
    https://mediafire.com/file/gsx5p1iwn35e1ni/Tests.zip

  • csampaio01csampaio01 PTMember ✭✭✭

    @seanyda You could solved it?

Sign In or Register to comment.