Hi,
Please find attached a simple project demonstrating the issue. Window1.xmal contains a print preview button and a XamDataGrid bound to the sample data. When the button is pressed, a print preview of the grid is shown.
I've added a style to override the record selectors with check boxes (as per the example in the feature browser). The check boxes appear correctly in the grid and are interactive.
The problem is the checkboxes all appear un-ticked when you print-preview. It appears to be ignoring any change to the visuals after the data has been initially loaded...? (I also created a control that I embedded within a data column, that contained a button and text. When the user clicks the button, the text randomly changes colour - which works fine in the UI, but none of the colours are shown in the printed version - all text is rendered in the original colour it was shown in).
Is this bug? is there any way to get it to print the grid as it appears at the time the print is invoked?
Regards,
Dave
Hi Matt,
Apologies for the very delayed response - the actual problem we have had all along is that images that appear fine in the grid at run time are not appearing correctly (or at all, in some cases) when we print preview the grid.
Back in October whilst trying to recreate the issue in a sample app, I noticed that the checkboxes tick marks were also not showing in the print preview. I assumed there was an underlying issue in printing any visual element created or modified after load, which is obviously not the case. We don't actually use checkboxes at all - I updated the original sample I attached with the suggested binding and saw it all worked (not actually sure why however! Looks rather strange that the IsChecked is being bound to the records Tag property).
Anyway, it didn't fix our issue and we didn't have time to investigate further. Now is that time! I *think* the issue we have is due to the way we are using images.
In your xamFeatureBrowser (xamDataGrid > Control Composition > Icons In Unbound Field example), you use a CellValuePresenter Template to add icons for Employee/Customer. I modified the source for this to add a print preview and it all works ok. I've tried creating a demo app to recreate the problem and that worked fine as well. Then I realised that in all cases where it works, the paths to the images are being hard-coded (either in XAML or code behind).
In our real application, all our images are stored in a database in Binary. We have an ImageStore class that serves up these images as MemoryStreams (it caches them in memory and gets them from the database if not already in the cache).
So, I now have a sample app (attached) that I think mimics our actual application enough to demonstrate the issue. The code isn't the neatest in the world, but essentially Window1 contains a xamDataGrid that is set up in the code behind. There's a very simple data class "Animal" with name and type properties that I bind to. I create a field layout in code, containing two UnboundFields (one for Name, one for Type). For the "Type" field, I create a CellValuePresenter template that contains an "AnimalTypeControl" instance. An animal is either "Mammal" or "Bird" and the AnimalTypeControl is used to not only display the previous string, but also an image representation of the type:
I realise my example code looks rather mad (could be done much simpler), but this is fairly representative of what we're doing in our actual app (where all grid columns etc are dynamic and setup at runtime from XML definitions).
The "AnimalTypeControl" is a ContentControl that binds it's content to its parents content (i.e. the CellValuePresenter). It also exposes an ImageSource property that is set when the control is initialized. The control looks at the underlying DataItem (the animal) to determine if it's Bird or Mammal and sets the ImageSource accordingly.
If you run the example as-is, all works ok. I'm using BitmapFrame.Create and passing in the URI of the image files to use in either case. As mentioned above, in our real application the images are being served from a store. If you uncomment the line at the very bottom of AnimalTypeControl.vb (in the SetupControl method), it will use a dummy ImageStore instead.
My dummy ImageStore has a single static method that serves images based on a string passed in. For simplicity (and because it also shows the same issue), I've made it serve FileStreams.
Running the sample now and pressing "Print Preview" results in the following:
The same "Mammal" image (although at different sizes!?) is used for all the rows - which is representative of what we are seeing in our real app.
I am totally lost as to what is going on here - I snooped the print preview and noticed all images have been turned into paths using an ImageBrush (don't know why they are shown at different sizes, all images start out as 32x32)... I really don't know why I'm getting no "Bird" images. If you put breakpoints on the two FileStream lines in ImageStore, it hits them both (exactly three times each, as expected) when rendering the initial grid - press print preview and it again hits them both three times each, but then a few more times each after that (again, don't know why).
So, at the end of the day - how can I get the xamDataGrid to show images that come from a stream (as opposed to hard coding all images as resources, which is not an option in our case)... that also show correctly when printed?
HI,
I am following up on this forum thread.
Do you require further assistance?
Sincerely, Matt Developer Support Engineer
HI David,
Our developers have completed their review of development issue 57497. They have determined that this is not a bug for the following reasons:
This was a problem with the sample since the CheckBox was not bound to anything. Update the sample with the following to see it work properly:
<CheckBox IsChecked="{Binding Path=(Record).Tag, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
If you have more information regarding this issue that may require a reevaluation, or require further explanation, please let me know.
Thanks for your sample application. I ran it and duplicated your issue. I will create a case for this issue and submit it for developer review.