如何更改NSTable选定的行背景颜色?
这里很好answer,但它适用于合适的观点。
现在,我看到的是我可以改变选定的hilight风格:
MyTAble.SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.Regular;
但这里只有3个选项;
None = -1L,
Regular,
SourceList
我尝试过以下解决方案:
patientListDelegate.SelectionChanged += (o, e) => {
var r = PatientTableView.SelectedRow;
var v = PatientTableView.GetRowView (r, false);
v.Emphasized = false;
};
它正常工作,但如果我最小化然后再次打开应用程序,仍然显示蓝色
答案 0 :(得分:0)
我在objective-c
中找到了答案Change selection color on view-based NSTableView
这是c#实现:
内部委托:
public override NSTableRowView CoreGetRowView (NSTableView tableView, nint row)
{
var rowView = tableView.MakeView ("row", this);
if (rowView == null) {
rowView = new PatientTableRow ();
rowView.Identifier = "row";
}
return rowView as NSTableRowView;
}
和自定义行:
public class PatientTableRow : NSTableRowView
{
public override void DrawSelection (CGRect dirtyRect)
{
if (SelectionHighlightStyle != NSTableViewSelectionHighlightStyle.None) {
NSColor.FromCalibratedWhite (0.65f, 1.0f).SetStroke ();
NSColor.FromCalibratedWhite (0.82f, 1.0f).SetFill ();
var selectionPath = NSBezierPath.FromRoundedRect (dirtyRect, 0, 0);
selectionPath.Fill ();
selectionPath.Stroke ();
}
}
}