Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Strange closure bug?

$
0
0

I have a strange bug with the Activated closure in the GetObjectValue method. The GetObjectValue is called regularly with the correct row number for each entry in the table column, but when I click on an item the row value inside the Activated closure is always 0.

Any idea how to workaround this?

public class ArtistsDataSource : NSTableViewDataSource { private readonly MusicLibrary _library;

public ArtistsDataSource(MusicLibrary library)
{
    _library = library;
}

public override int GetRowCount (NSTableView tableView)
{
    return _library.Artists.Count ();
}

public override NSObject GetObjectValue (NSTableView tableView, NSTableColumn tableColumn, int row)
{
    NSButtonCell cell = tableColumn.DataCell as NSButtonCell;

    if(cell != null)
    {
        var artistId = _library.Artists [row].Id;
        var artistName = _library.Artists [row].Name;

        cell.Title = artistName;
        cell.Activated += (sender,e) => {
            Console.WriteLine ("row clicked: {0}", row); 
        };
    }

    return tableColumn.DataCell;
}

}


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>