Forum Xamarin.Mac
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Collection view Cell - Overlapping issue

EswaraprabuEswaraprabu Member ✭✭
edited September 16 in Xamarin.Mac

I'm using collection view in my Mac app.

Wile entering full screen mode the first cell is getting overlapped. please find the images

I used .xib for the cell

Please find the code below. Kindly help me on this.

Thanks

DataSource:

public class CustomDeckDataSource : NSCollectionViewDataSource
{
    List<string> deckText = new List<string>();
    public CustomDeckDataSource( List<string> _deckText)
    {
        this.deckText = _deckText;
        ParentCollectionView = parent;
        playDeckView = view;
    }

    public override nint GetNumberOfSections(NSCollectionView collectionView)
    {
        return 1;
    }

    public override NSCollectionViewItem GetItem(NSCollectionView collectionView, NSIndexPath indexPath)
    {

        var item = new CustomDeckItems("CustomDeckItems", NSBundle.MainBundle);



        item.UpdateCell( deckText[(int)indexPath.Item]);

        return item;
    }

    public override nint GetNumberofItems(NSCollectionView collectionView, nint section)
    {
        return deckText.Count;
    }
}

Cell Class:

public partial class CustomDeckItems : AppKit.NSCollectionViewItem
{

    NSTextField test;

    [Weak] PlayDeckView playDeckView = null;
    public CustomDeckItems(IntPtr handle) : base(handle)
    {
    }

    // Called when created directly from a XIB file
    [Export("initWithCoder:")]
    public CustomDeckItems(NSCoder coder) : base(coder)
    {

    }


    public CustomDeckItems(string nibName, NSBundle nibBundle) : base(nibName, nibBundle)
    {


    }

    public CustomDeckItems() : base("DeckItems", NSBundle.MainBundle)
    {
    }

    public override void ViewDidAppear()
    {
        base.ViewDidAppear();
        this.View.Layer.BorderColor = NSColor.FromRgb(126, 200, 200).CGColor;
        this.View.Layer.BorderWidth = 1.0f;
    }
    internal void UpdateCell( string _text)
    {
        test = new NSTextField();
        test.StringValue = _text;
        this.View.AddSubview(test);
    }
}

ViewController:

List<string> deckLables = new List<string>();
PlayDeckDataSource playDeckDataSource;

 public override void ViewDidLoad()
    {
        base.ViewDidLoad();


        deckLables.Add("one");
        deckLables.Add("one");
        deckLables.Add("one");
        deckLables.Add("one");
        deckLables.Add("one");
        deckLables.Add("one");
        deckLables.Add("one");
        deckLables.Add("one");


        this.DeckCollectionView.RegisterClassForItem(typeof(CustomDeckItems), "DeckItems");

        var flowlayout = new NSCollectionViewFlowLayout()
        {
            ItemSize = new CGSize(180, 40),
            SectionInset = new NSEdgeInsets(5, 5, 5, 5),
            // ScrollDirection = NSCollectionViewScrollDirection.Vertical
        };
        this.DeckCollectionView.CollectionViewLayout = flowlayout;

        customDeckDataSource = new CustomDeckDataSource(this, this.DeckCollectionView, deckLables);
        DeckCollectionView.DataSource = customDeckDataSource;
        DeckCollectionView.ReloadData();

}

Best Answer

Answers

Sign In or Register to comment.