0

如何更改 NSTable 选定行的背景颜色?

这是很好的答案,但它适用于视图。

现在,我看到的是我可以更改选定的高亮样式:

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;
                    };

它工作正常,但如果我最小化然后再次打开应用程序,仍然显示蓝色

4

1 回答 1

0

我在objective-c中找到了答案

在基于视图的 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 ();
            }
        }
    }
于 2016-11-16T11:00:24.513 回答