问题
I am working on a Xamarin Mac application and am currently creating a newsfeed list.
What I would like to have is that when the user click on one of the row I do some stuff (open up a browser and show the full story).
Here is how my custom cell (row) looks like.
public class CustomLatestNewsCell : NSView
{
public NSText Title;
public NSText Date;
public NSText Details;
public CustomLatestNewsCell()
{
Title = new NSText();
Title.Frame = new CoreGraphics.CGRect(0, 120, 300, 70);
Title.TextColor = NSColor.FromSrgb((nfloat)0.207, (nfloat)0.576, (nfloat)0.639, (nfloat)1);
Title.Font = NSFont.UserFontOfSize(20);
Title.Editable = false;
Title.Selectable = false;
this.AddSubview(Title);
Date = new NSText();
Date.Frame = new CoreGraphics.CGRect(0, 25, 300, 30);
Date.TextColor = NSColor.FromSrgb((nfloat)0.702, (nfloat)0.702, (nfloat)0.702, (nfloat)1);
Date.Editable = false;
Date.Selectable = false;
this.AddSubview(Date);
Details = new NSText();
Details.Frame = new CoreGraphics.CGRect(310, 120, 550, 32);
Details.TextColor = NSColor.FromSrgb((nfloat)0.5, (nfloat)0.5, (nfloat)0.5, (nfloat)1);
Details.Editable = false;
Details.Selectable = false;
this.AddSubview(Details);
this.Frame = new CoreGraphics.CGRect(0, 0, 850, 150);
}
}
I have tried a lot of things but there doesn't seem to be a click/activated/somethingElse function which will trigger when I click on anything in the cell. The only thing that works is
public override void SelectionIsChanging(NSNotification notification)
{
var row = (NSTableView)notification.Object;
var selectedRow = row.SelectedRow;
if(selectedRow < 0)
return;
var selectedFeed = feed[(int)selectedRow];
row.DeselectAll(row);
NSWorkspace ws = new NSWorkspace();
NSError error = new NSError();
ws.OpenURL(new NSUrl(selectedFeed.Url),
NSWorkspaceLaunchOptions.AllowingClassicStartup,
new NSDictionary(),
out error);
}
but in this case the user has to click on some "empty" parts of the row. Is there a way that I catch a click on any of the parts in the cell and then trigger the action?
I am quite new to Mac development so I am quite lost at the moment
来源:https://stackoverflow.com/questions/29920444/nstable-row-click-event