安装:
Install-Package Cgdata.FastWpfGrid
前台代码:
xmlns:FastWpfGrid="clr-namespace:FastWpfGrid;assembly=FastWpfGrid"
<FastWpfGrid:FastGridControl
x:Name="grid1"
IsReadOnly="True"
Model="{Binding DataModel}">
<FastWpfGrid:FastGridControl.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding CopyCommand}" Header="复制" />
</ContextMenu>
</FastWpfGrid:FastGridControl.ContextMenu>
</FastWpfGrid:FastGridControl>
后台绑定的代码:
using CgdataBase;
using FastWpfGrid;
using MessageBox = NetworkMonitor.Views.MessageBox;
namespace NetworkMonitor.Models;
public class GridModel : FastGridModelBase
{
private readonly byte[] _data;
private readonly int _columnCount;
private readonly int _rowCount;
public GridModel(byte[] data, int columnCount) : base()
{
_data = data;
_columnCount = columnCount;
if (data.HadItems())
_rowCount = (data.Length + columnCount - 1) / columnCount;
else
_rowCount = 0;
}
public override int ColumnCount
{
get { return _columnCount; }
}
public override int RowCount
{
get { return _rowCount; }
}
public override string GetCellText(int row, int column)
{
if (_data.IsNullOrEmpty())
return "";
var offset = row * ColumnCount + column;
if (offset < _data.Length)
return _data[offset].ToString("X2");
return "";
}
public override void HandleCommand(IFastGridView view, FastGridCellAddress address, object commandParameter, ref bool handled)
{
base.HandleCommand(view, address, commandParameter, ref handled);
if (commandParameter is string)
MessageBox.Show(commandParameter.ToString());
}
public override int? SelectedRowCountLimit
{
get { return 100; }
}
public override void HandleSelectionCommand(IFastGridView view, string command)
{
MessageBox.Show(command);
}
public override IFastGridCell GetColumnHeader(IFastGridView view, int column)
{
var cell = new FastGridCellImpl();
cell.AddTextBlock(column.ToString().PadLeft(3, ' ') + " ").IsBold = true;
return cell;
}
public override string GetRowHeaderText(int row)
{
return row.ToString();
}
}
标签:FastWpfGrid,columnCount,return,int,override,Cgdata,data,public
From: https://www.cnblogs.com/wzwyc/p/18034234