objective-ccocoanstableviewxamarin.macnstablecellview

Change highlight color of NSTableView selected row


how to change NSTable selected row background color?

here is good answer, but it is for uitable view .

For now,what I see is that I can change selected hilight style :

MyTAble.SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.Regular;

But here is only 3 options;

None = -1L,
        Regular,
        SourceList

I have tried following solution :

patientListDelegate.SelectionChanged += (o, e) => {
                        var r = PatientTableView.SelectedRow;
                        var v = PatientTableView.GetRowView (r, false);
                        v.Emphasized = false;
                    };

It works normally , but if I minimize and then open application again , still shows blue color


Solution

  • I found answer in objective-c

    Change selection color on view-based NSTableView

    Here is c# implementation:

    inside delegate :

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

    and custom row :

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