2016-11-10 97 views
0

如何更改NSTable選定的行背景顏色?更改NSTableView選定行的高亮顏色

這裏不錯answer,但它是適合視圖。

現在,我所看到的是,我可以改變選擇的高亮風格:

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

我發現在Objective-C

答案

Change selection color on view-based NSTableView

這裏是c#實現entation:

內委託:

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