Forum Xamarin Xamarin.Forms

Content of a frame that is the View of a ViewCell appear on top of other rows in the list - iOS only

Chasy_AChasy_A Member ✭✭
edited July 6 in Xamarin.Forms

Hi,

I updated to the latest Xamarin.Forms version (4.7.0.1080) and now a list view I have in my project is totally messed up - the template of the list view is set to a custom view cell that it's View is set to a frame and now the content of the rows appear on top of each other.
I found this same problem in this sample - https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/boxview-listviewcolors (see screenshot)

Does anyone have a fix for this problem?

Thanks!

Best Answers

Answers

  • Chasy_AChasy_A Member ✭✭

    Thanks @Jarvan,
    my code is written in C# and when I add the CachingStrategy I get an error: Property or indexer 'ListView.CachingStrategy' cannot be assigned to -- it is read only

  • Chasy_AChasy_A Member ✭✭

    Thank you @Jarvan!
    I tried it but in my project it fixed only partially - I have a frame with a label in it that is added to the view cell OnBindingContextChanged and as soon as I start to scroll, the frames start to overlap with each other....
    You can try it in the Xamrin's sample I linked - add to the ViewCell BindingContentChange:

    private void viewCell_BindingContextChanged(object sender, EventArgs e)
    
        {
    
            var viewCell = sender as ViewCell;
    
            if (viewCell == null)
    
            {
    
                return;
    
            }
    
            var contentView = viewCell.View as ContentView;
    
            var frame = contentView.Content as Frame;
    
            var stack = frame.Content as StackLayout;
    
            stack.Children.Add(new Frame { Content = new Label { Text = "111" } });
    
        }
    
  • JarvanJarvan Member, Xamarin Team Xamurai

    I have a frame with a label in it that is added to the view cell OnBindingContextChanged and as soon as I start to scroll, the frames start to overlap with each other....

    This is because the collectionView reuse the cell repeatedly. To avoid this issue, don't add or remove a control to the cell's content. Instead, create a new view layout to replace the previous one. Or you could add the control to the cell at begining and set it invisible, change the control to be visible in the BindingContextChanged event.

    private void ViewCell_BindingContextChanged(object sender, EventArgs e)
    {
        var viewCell = sender as ViewCell;
    
        if (viewCell == null)
    
        {
            return;
        }
    
        var contentView = viewCell.View as ContentView;
        var frame = contentView.Content as Frame;
        //var stack = frame.Content as StackLayout;
    
        frame.Content = new StackLayout { Children = { ... } } };
    }
    
  • Chasy_AChasy_A Member ✭✭

    @Jarvan , I tried your suggestion to recreate the view but it does not look good in my project,
    In my project in the OnBinfingContextChange method I'm fetching data from a server based on data of the BindingContext and display it in a frame that I add to the existing view, if I create a new view or replace it the content of the cells jumps on the screen and each cell displays it content at a different second so the data order does not look good...
    I marked you answer as accepted because basically it does help...
    Thanks!

Sign In or Register to comment.