Xamarin NSTableView隐藏列,颜色特定单元格,颜色特定行

时间:2015-09-25 21:54:33

标签: macos colors xamarin nstableview

我正在尝试在我的项目中实现NSTableView并用特定数据填充它。这很好用。但现在,我希望能够隐藏一些列,颜色特定单元格或颜色特定行。我在java中做了类似的东西,但我真的不知道要在Xamarin中做到这一点:Mac。

以下是我的代表的代码:

public class Mp3FileTableDelegate : NSTableViewDelegate {

    private const string CellIdentifier = "FileCell";

    private Mp3FileDataSource DataSource;

    public Mp3FileTableDelegate (Mp3FileDataSource datasource) {
        this.DataSource = datasource;
    }

    public override NSView GetViewForItem (NSTableView tableView, NSTableColumn tableColumn, nint row) {
        // This pattern allows you reuse existing views when they are no-longer in use.
        // If the returned view is null, you instance up a new view
        // If a non-null view is returned, you modify it enough to reflect the new data
        NSTextField view = (NSTextField)tableView.MakeView (CellIdentifier, this);
        if (view == null) {
            view = new NSTextField ();
            view.Identifier = CellIdentifier;
            view.BackgroundColor = NSColor.Clear;
            view.Bordered = false;
            view.Selectable = false;
            view.Editable = true;
            view.EditingEnded += (sender, e) => {
                SetNewValueInMp3File (DataSource.AudioFiles [(int)row], tableColumn, view.StringValue);
            };
        }

        AudioFile audioFile = DataSource.AudioFiles [(int)row];

        // Setup view based on the column selected
        switch (tableColumn.Title) {
        case "Path":
            view.StringValue = audioFile.getPathWithFilename ();
            break;
        }
        if (audioFile.GetType () == typeof(Mp3File)) {
            Mp3File mp3File = (Mp3File)audioFile;

            switch (tableColumn.Title) {
            case "Artist":
                view.StringValue = mp3File.Artist;
                break;
            case "Title":
                view.StringValue = mp3File.Title;
                break;
            case "Album":
                view.StringValue = mp3File.Album;
                break;
            case "BPM":
                view.StringValue = mp3File.BPM;
                break;
            case "Comment":
                view.StringValue = mp3File.Comment;
                break;
            case "Year":
                view.StringValue = mp3File.Year;
                break;
            case "Key":
                view.StringValue = mp3File.InitialKey;
                break;
            case "Quality":
                view.StringValue = mp3File.Album;
                break;
            case "Length":
                view.StringValue = mp3File.Album;
                break;
            }
        }
        return view;
    }


    private void SetNewValueInMp3File (AudioFile file, NSTableColumn tableColumn, String value) {

        if (file.GetType () == typeof(Mp3File)) {
            Mp3File mp3File = (Mp3File)file;

            switch (tableColumn.Title) {
            case "Artist":
                mp3File.Artist = value;
                break;
            case "Title":
                mp3File.Title = value;
                break;
            case "Album":
                mp3File.Album = value;
                break;
            case "BPM":
                mp3File.BPM = value;
                break;
            case "Comment":
                mp3File.Comment = value;
                break;
            case "Year":
                mp3File.Year = value;
                break;
            case "Key":
                mp3File.InitialKey = value;
                break;
            }
        }
    }
}

这里是我的数据源:

    public class Mp3FileDataSource  : NSTableViewDataSource {

    public List<AudioFile> AudioFiles = new List<AudioFile> ();

    public Mp3FileDataSource () {

    }

    public override nint GetRowCount (NSTableView tableView) {
        return AudioFiles.Count;
    }
}

如果有人能帮我一点,我会非常感激。

由于

0 个答案:

没有答案