FlexGrid には、セルのコンテンツを完全に制御できます。UIView クラスと GridCellType 列挙を追加することで各列をカスタマイズでき、セルコンテンツをコード内で完全にカスタマイズできます。
次の図は、パフォーマンスを表すセルテンプレートとして C1Gauge を設定したときの FlexGrid を示しています。
次のコード例は、FlexGrid コントロールにカスタムセルコンテンツを追加する方法を示します。次の例では、「クイックスタート」セクションで作成したサンプルを使用します。
C# |
コードのコピー
|
---|---|
public class MainActivity : Activity { int count = 1; protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // 「メイン」レイアウトリソースからビューを設定する SetContentView(Resource.Layout.Main); var grid = FindViewById<FlexGrid>(Resource.Id.Grid); grid.AutoGenerateColumns = false; grid.Columns.Add(new GridColumn() { Binding = "FirstName", Width = GridLength.Star }); grid.Columns.Add(new GridColumn() { Binding = "LastName", Width = GridLength.Star }); grid.Columns.Add(new GridBulletGraphColumn() { Binding = "OrderTotal", Header = "注文合計", Width = GridLength.Star }); var data = Customer.GetCustomerList(100); grid.ItemsSource = data; } } public class GridBulletGraphColumn : GridColumn { protected override object GetCellContentType(GridCellType cellType) { if (cellType == GridCellType.Cell) { return typeof(C1BulletGraph); } else { return base.GetCellContentType(cellType); } } protected override View CreateCellContent(GridCellType cellType, object cellContentType) { if (cellType == GridCellType.Cell) { var gauge = new C1BulletGraph(Grid.Context); gauge.Max = 10000; gauge.Target = 7000; gauge.Bad = 1000; gauge.Good = 6000; gauge.IsReadOnly = true; return gauge; } else { return base.CreateCellContent(cellType, cellContentType); } } protected override void BindCellContent(View cellContent, GridCellType cellType, GridRow row) { if (cellType == GridCellType.Cell) { var gauge = cellContent as C1BulletGraph; gauge.Value = (double)GetCellValue(cellType, row); } else { base.BindCellContent(cellContent, cellType, row); } } } |