나는 마침내 효과를 낼 수있었습니다. 그것을 시험해보고 싶은 누군가를위한 몇몇 부호는 여기있다. 기본적으로 필요한 기능을 위해 NSTableViewDelegate
을 작성해야합니다. 이 구현은 또한 컨트롤 또는 아무것도 캐시하지 않습니다. Cocoa API documentation은 식별자를 사용하여 컨트롤 등을 재사용하지만 식별자 필드는 MonoMac에서 get-only입니다.
내 데이터 소스 자체에 NSTableViewDelegate
기능을 구현하는 일이 끝났습니다. 물론이 모든 것이 최선의 방법은 아니지만 모범 사례가 무엇인지 잘 모르겠습니다. 여기
데이터 소스 클래스의 :
class MyTableViewDataSource : NSTableViewDataSource
{
private NSObject[] _data;
// I'm coming from an NSCollectionView, so my data is already in this format
public MyTableViewDataSource(NSObject[] data)
{
_data = data;
}
public override int GetRowCount(NSTableView tableView)
{
return _data.Length;
}
#region NSTableViewDelegate Methods
public NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, int row)
{
// MyViewClass extends NSView
MyViewClass result = tableView.MakeView("MyView", this) as MyViewClass;
if (result == null)
{
result = new MyViewClass(_data[row]);
result.Frame = new RectangleF(0, 0, tableView.Frame.Width, 100); // height doesn't matter since that is managed by GetRowHeight
result.NeedsDisplay = true;
// result.Identifier = "MyView"; // this line doesn't work because Identifier only has a getter
}
return result;
}
public float GetRowHeight(NSTableView tableView, int row)
{
float height = FigureOutHeightFromData(_data[row]); // run whatever algorithm you need to get the row's height
return height;
}
#endregion
}
그리고 여기 프로그래밍 테이블 생성 조각의 하나는 수동으로 행의 높이를 계산해야하기 때문에 그래서
var tableView = new NSTableView();
var dataSource = new MyTableViewDataSource();
tableView.DataSource = dataSource;
tableView.HeaderView = null; // get rid of header row
tableView.GetViewForItem = dataSource.GetViewForItem;
tableView.GetRowHeight = dataSource.GetRowHeight;
AddSubView(tableView);
, 그것은 완벽한 StackPanel
아니다 ,하지만 아무것도없는 것보다 낫습니다.