tôi sử dụng đối tượng NodeView số liệu đầu ra cho người sử dụng theo cách này (Gtk # hướng dẫn):Gtk # NodeView hàng màu
[Gtk.TreeNode (ListOnly=true)]
public class MyTreeNode : Gtk.TreeNode {
string song_title;
public MyTreeNode (string artist, string song_title)
{
Artist = artist;
this.song_title = song_title;
}
[Gtk.TreeNodeValue (Column=0)]
public string Artist;
[Gtk.TreeNodeValue (Column=1)]
public string SongTitle {get { return song_title; } }
}
Gtk.NodeStore store;
Gtk.NodeStore Store
{
get {
if (store == null)
{
store = new Gtk.NodeStore (typeof(MyTreeNode));
store.AddNode (new MyTreeNode ("The Beatles", "Yesterday"));
store.AddNode (new MyTreeNode ("Peter Gabriel", "In Your Eyes"));
store.AddNode (new MyTreeNode ("Rush", "Fly By Night"));
}
return store;
}
}
protected void OnButton1Clicked (object sender, EventArgs e)
{
// Create a column with title Artist and bind its renderer to model column 0
nodeview1.AppendColumn ("Artist", new Gtk.CellRendererText(), "text", 0);
// Create a column with title 'Song Title' and bind its renderer to model column 1
nodeview1.AppendColumn ("Song Title", new Gtk.CellRendererText(), "text", 1);
nodeview1.ShowAll();
nodeview1.NodeStore=Store;
}
Nhưng làm thế nào tôi có thể tô màu cho một số hàng của NodeView ("The Beatles" - "Hôm qua ", ví dụ)? Tôi đã cố gắng để làm điều đó bằng cách thay đổi của NodeView Style: Backgrounds, BaseColors, Foregrounds và khác nhưng nó không hoạt động.
Chỉnh sửa: Tôi chỉ nhận ra, rằng tôi có thể thay đổi màu của cột theo cách này:
protected void OnButton1Clicked (object sender, EventArgs e)
{
// Create a column with title Artist and bind its renderer to model column 0
nodeview1.AppendColumn ("Artist", new Gtk.CellRendererText(), "text", 0);
// Create a column with title 'Song Title' and bind its renderer to model column 1
nodeview1.AppendColumn ("Song Title", new Gtk.CellRendererText(), "text", 1);
nodeview1.ShowAll();
nodeview1.NodeStore=Store;
nodeview1.Columns[0].Cells[0].CellBackgroundGdk=new Gdk.Color(0,255,0);
}
nhưng làm thế nào tôi có thể thay đổi màu sắc của một tế bào cụ thể?
Tôi không thể thử ngay bây giờ, do đó cũng giống như nhận xét: Bạn có thể xem xét thay thế trình kết xuất ô bằng một thứ gì đó tùy chỉnh lấp đầy ô bằng một tiện ích có màu thích hợp. –
Tôi không thể tìm thấy bất cứ điều gì như nó. Nodeview không có một số sự kiện cho ô – Mixim
Nó không phải là một sự kiện. Bạn hiện đang sử dụng lớp 'Gtk.CellRendererText', nhưng thay vào đó, bạn có thể lấy được lớp trình kết xuất ô của riêng bạn từ [' Gtk.CellRenderer'] (http://docs.go-mono.com/?link= T% 3aGtk.CellRenderer) bằng cách ghi đè phương thức 'GetSize' và' Render' của nó. –