This question is locked. New answers and comments are not allowed.
I define a ImageColumn.It inherits from a GridViewDataColumn.My version is Q3.
The data source of the grid is only one row.But when I scroll the horizonal scroll bar,the grid and the projects will crash.I set a break point in CreateCellElement.It seems like this method is always executing.I seems like a dead cycling.I do not what happening.Can you
analyse the reason for me?Thank you very much.
The data source of the grid is only one row.But when I scroll the horizonal scroll bar,the grid and the projects will crash.I set a break point in CreateCellElement.It seems like this method is always executing.I seems like a dead cycling.I do not what happening.Can you
analyse the reason for me?Thank you very much.
| public class UserImage |
| { |
| public byte[] ImageStream; |
| public string ImageUrl { get; set; } |
| public string ImageName { get; set; } |
| } |
| public class ImageColumn : GridViewDataColumn |
| { |
| private string _DispalyMemberPath = string.Empty; |
| public string DispalyMemberPath |
| { |
| get |
| { |
| return _DispalyMemberPath; |
| } |
| set |
| { |
| _DispalyMemberPath = value; |
| } |
| } |
| private string GetUrl(object dataItem) |
| { |
| PropertyInfo CurProp = dataItem.GetType().GetProperty(_DispalyMemberPath); |
| UserImage img = CurProp.GetValue(dataItem, null) as UserImage; |
| if (img == null) |
| { |
| return string.Empty; |
| } |
| if (img.ImageUrl == null) |
| { |
| return string.Empty; |
| } |
| else |
| { |
| return img.ImageUrl; |
| } |
| } |
| private byte[] GetImageStream(object dataItem) |
| { |
| PropertyInfo CurProp = dataItem.GetType().GetProperty(_DispalyMemberPath); |
| UserImage img = CurProp.GetValue(dataItem, null) as UserImage; |
| if (img == null) |
| { |
| return new byte[0]; |
| } |
| if (img.ImageStream == null) |
| { |
| return new byte[0]; |
| } |
| else |
| { |
| return img.ImageStream; |
| } |
| } |
| private string GetImageName(object dataItem) |
| { |
| PropertyInfo CurProp = dataItem.GetType().GetProperty(_DispalyMemberPath); |
| UserImage img = CurProp.GetValue(dataItem, null) as UserImage; |
| if (img == null) |
| { |
| return string.Empty; |
| } |
| if (img.ImageName == null) |
| { |
| return string.Empty; |
| } |
| else |
| { |
| return img.ImageName; |
| } |
| } |
| public Stream BytesToStream(byte[] bytes) |
| { |
| Stream stream = new MemoryStream(bytes); |
| return stream; |
| } |
| public override FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem) |
| { |
| StackPanel panel = new StackPanel(); |
| var cellImage = new Image(); |
| BitmapImage img = new BitmapImage(); |
| string imageUri = GetUrl(dataItem); |
| byte[] imageStream = GetImageStream(dataItem); |
| if (imageUri != string.Empty) |
| { |
| img.UriSource = new Uri(imageUri, UriKind.RelativeOrAbsolute); |
| } |
| else if (imageStream.Length > 0) |
| { |
| img.SetSource(BytesToStream(imageStream)); |
| } |
| cellImage.Source = img; |
| panel.Children.Add(cellImage); |
| var imageName = GetImageName(dataItem); |
| if (imageName != string.Empty) |
| { |
| TextBlock txt = new TextBlock(); |
| txt.Text = imageName; |
| panel.Children.Add(txt); |
| } |
| return panel; |
| } |
| } |