0

我在我的项目中使用 Telerik RadGridView。我想在列中显示图像。

                GridViewImageColumn col1 = new GridViewImageColumn();
                col1.Width = 100;
                col1.DataMemberBinding = new Binding("id");
                col1.Header = "PhotoByConverter";
                col1.DataMemberBinding.Converter = new ThumbnailConverter();
                grid.Columns.Add(col1);


                GridViewDataColumn col2 = new GridViewDataeColumn();
                col2.Width = 100;
                col2.DataMemberBinding = new Binding("firstName");
                col2.Header = "Person name";
                grid.Columns.Add(col2);

                Grid.ItemsSource=DataTable;

第一列不是 wokrs,但第二列工作正常。我将转换器用于如下所示的图像

    public class ThumbnailConverter : IValueConverter
    {

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
                    IEnumerable<thumbNail> result = from n in thumbnails
                                        where n.personID == value.ToString()
                                        select n;


        if (result != null && result.First().thumbnail != null)
        {
            return result.First().thumbnail.file;
        }
        else
        {
            return null;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new Exception("The method or operation is not implemented.");
    }
   }

我通过人的 id 缩略图找到并将其设置为 GridViewImageColumn 的数据。我检查了调试器转换器是否正常工作。我无法理解为什么它不起作用。有任何想法吗?

4

1 回答 1

0

我找到了解决这些问题的方法。唯一需要的是在方括号中使用属性名称

    GridViewImageColumn col1= new GridVeiwImageColumn();
    col1.DataMemberBinding = new Binding("[id]");
于 2010-04-26T10:29:44.893 回答