「Xamarin.MacのNSTableViewでNSTableViewSourceを使う」の版間の差分

138行目: 138行目:
             return true;
             return true;
         }
         }
</source>
===セルのデザインを変える===
セルのデザインをいじくるにはデータソースの以下のメソッドをオーバーライドしてその中でいじくりまわす。
セルは初期状態でDrawsBackgroundプロパティがfalseに設定されており背景描画が無効化されているようなので、trueに設定したのちに各種操作をしている。
<source lang="csharp">
    public class StudyTableViewSource : NSTableViewSource, IList<Study>
    {
        // 〜〜〜省略〜〜〜
        public override void WillDisplayCell(NSTableView tableView, NSObject cell, NSTableColumn tableColumn, int row)
        {
            // 編集不可カラムの背景色を少し暗くしてみる
            if (tableColumn.Editable == false)
            {
                if (cell is NSTextFieldCell)
                {
                    var textfield = cell as NSTextFieldCell;
                    textfield.DrawsBackground = true;
                    textfield.BackgroundColor = NSColor.FromSrgb(0.9f, 0.9f, 0.9f, 1.0f);
                }
            }
        }
    }
</source>
</source>