Syncfusion数据网格无法显示照片

时间:2017-05-08 22:19:17

标签: c# ios datagrid syncfusion

我有一个员工数据表,我想在syncfusion iOS数据网格中显示。数据表中的一个字段是包含员工的照片字段。照片。我的问题是网格中的这个照片列只显示System.Byte[],而不是照片。

我想我必须以某种方式格式化GridAutoGeneratingColumns事件中的列,但我没有到达那里。我正在使用`xamarin.ios和C#,并感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:0)

您的要求可以通过两种方式实现。如果您使用的是旧版本的SfDataGrid,则可以使用GridTextColumn.UserCellType属性在SfDataGrid中加载图像,否则可以将SfDataGrid更新为最新版本(15.2.0.40)并使用GridImageColumn在SfDataGrid中加载图像。图像的构建操作应该是EmbeddedResource或BundleResource。

请参考以下代码示例,使用GridTextColumn.UserCellType属性加载图像。

GridTextColumn customerImageColumn = new GridTextColumn();
customerImageColumn.UserCellType = typeof(GridImageCell);
customerImageColumn.MappingName = "CustomerImage";
customerImageColumn.HeaderText = "Image";

//GridImageCell.cs
public class GridImageCell : GridCell
    {
        private UIImageView imageview;
        CoreGraphics.CGRect framespec = new CoreGraphics.CGRect();

        public GridImageCell()
        {
            imageview = new UIImageView();
            this.CanRenderUnLoad = false;
        }

        protected override void UnLoad()
        {
            this.RemoveFromSuperview();
        }

        public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            if (imageview.Superview == null)
            {
                this.AddSubview(imageview);
                framespec = new CoreGraphics.CGRect(20, 3, 60, (nfloat)DataColumn.Renderer.DataGrid.RowHeight - 5);
            }

            imageview.Frame = framespec;
            imageview.Image = (UIImage)DataColumn.RowData.GetType().GetProperty("CustomerImage").GetValue(DataColumn.RowData);
        }
}

请参考以下代码示例,使用GridImageColumn加载图像。

GridImageColumn customerImageColumn = new GridImageColumn();
customerImageColumn.MappingName = "CustomerImage";
customerImageColumn.HeaderText = "Image";

// Model class - The type of the “CustomerImage” should be UIImage
public UIImage CustomerImage  
{
    get
    {
        return customerImage;
    }
    set
    {
        customerImage = value;
    }
}

// Repository class – the image should be set to the “CustomerImage” property as highlighted
public List<OrderInfo> GetBankDetails(int count)
{
    List<OrderInfo> bankDetails = new List<OrderInfo>();

    for (int i = 1; i <= count; i++)
    {
        var ord = new OrderInfo()
        {
            CustomerID = i,
            BranchNo = BranchNo[random.Next(15)],
            Current = CurrentBalance[random.Next(15)],
            Savings = Savings[random.Next(15)],
            CustomerName = Customers[random.Next(15)],
            BalanceScale = random.Next(1, 100),
            IsOpen = ((i % random.Next(1, 10) > 2) ? true : false),
            CustomerImage = Imagehelper.ToUIImage(new ImageMapStream(LoadResource("Image1.png").ToArray())),
            Transactions = random.Next(80)
        };
        bankDetails.Add(ord);
    }
    return bankDetails;
}