Xamarin NSTable行单击事件
我正在开发Xamarin Mac应用程序,目前正在创建新闻提要列表 我想要的是,当用户单击其中一行时,我会做一些事情(打开浏览器并显示完整的故事) 下面是我的自定义单元格(行)的外观Xamarin NSTable行单击事件,xamarin,xamarin.mac,Xamarin,Xamarin.mac,我正在开发Xamarin Mac应用程序,目前正在创建新闻提要列表 我想要的是,当用户单击其中一行时,我会做一些事情(打开浏览器并显示完整的故事) 下面是我的自定义单元格(行)的外观 public class CustomLatestNewsCell : NSView { public NSText Title; public NSText Date; public NSText Details; public CustomLatestNewsCell()
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);
}
}
我已经尝试了很多方法,但似乎没有一个click/activated/somethingElse函数,当我点击单元格中的任何东西时,它都会触发。唯一有效的是
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);
}
公共覆盖无效选择更改(NSNotification通知)
{
var row=(NSTableView)notification.Object;
var selectedRow=row.selectedRow;
if(selectedRow<0)
返回;
var selectedFeed=feed[(int)selectedRow];
行。取消全部(行);
NSWorkspace ws=新的NSWorkspace();
NSError error=新的NSError();
OpenURL(新的NSUrl(selectedFeed.Url),
NSWorkspaceLaunchOptions.AllowingClassicStartup,
新建NSDictionary(),
输出误差);
}
但在这种情况下,用户必须单击行的某些“空”部分。有没有一种方法可以让我点击单元格中的任何部分,然后触发动作
我是Mac开发的新手,所以我现在很迷茫