【问题标题】:Syncfusion data grid can't display photoSyncfusion数据网格无法显示照片
【发布时间】:2017-05-12 09:15:02
【问题描述】:

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

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

【问题讨论】:

    标签: c# ios datagrid syncfusion


    【解决方案1】:

    您的要求可以通过两种方式实现。如果您使用的是旧版本的 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;
    }
    

    【讨论】:

    • 非常感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多