Good morning all:
I'm having a problem getting an image to populate the GridImageColumn in the DataGrid. The code below is what I'm using, I can confirm that the image is saved to the application local location in HoldImages folder and is named ImageHold.png. I can also see that ImageDisplay class has the Uri loaded as the image uri source and that that the class is the itemsource for DisplayGrid. It all looks like it should work, however when it goes to print it throws a "value cannot be null" error, it does not indicate what value is null.
john
System.ArgumentNullException occurred
HResult=0x80004003
Message=Value cannot be null.
Source=<Cannot evaluate the exception source>
StackTrace:
at Syncfusion.UI.Xaml.Grid.PrintManagerBase..ctor(ICollectionViewAdv view)
at Syncfusion.UI.Xaml.Grid.SfDataGrid.Print()
at Estimation_And_Design.Controls.ReportUserControl.<AddImageAsync>d__8.MoveNext() in C:\Users\johnw\documents\visual studio 2017\Projects\Estimation And Design\Estimation And Design\Controls\ReportUserControl.xaml.cs:line 94
public ObservableCollection<ImageLinkModel> ImgCollection = new ObservableCollection<ImageLinkModel>();
public ObservableCollection<WriteableBitmap> ImageCollection = new ObservableCollection<WriteableBitmap>();
public class ImageLinkModel
{
public BitmapImage ImageDisplay { get; set; }
}
public async void AddImageAsync()
{
int ImageIndex = 1;
foreach (WriteableBitmap item in ImageCollection)
{
// First save the image to local, replace if it exits
await SaveBitmapToFileAsync(item, "ImageHold" + ImageIndex.ToString() + ".png");
// Use the saved image to populate the class
ImageLinkModel ILM = new ImageLinkModel();
ILM.ImageDisplay = new BitmapImage(new Uri(string.Format("ms-appdata:///local/HoldImages/ImageHold" + ImageIndex.ToString() + ".png"), UriKind.Absolute));
ImgCollection.Add(ILM);
ImageIndex = ImageIndex + 1;
}
// Class added as image source
DetailGrid.ItemsSource = ImgCollection;
// Create the column
this.DetailGrid.Columns.Add(new GridImageColumn() { HeaderText = "Design", MappingName = "ImageDisplay", Stretch = Stretch.Uniform });
// Print the grid
DetailGrid.PrintSettings = new PrintSettings();
DetailGrid.PrintSettings.AllowColumnWidthFitToPrintPage = true;
DetailGrid.Print();
}