1

I have a WPF Library project, and when i run it in visual studio it runs perfect, and the print function works as it should, but when i open the project from another application and print it, the checkboxes are always empty.

I tried it without binding and with binding, but the checkboxes are always empty.

How is this possible??

Checkbox is like this:

<CheckBoc IsChecked="true"/>

and when i print it from visual studio it's checked but when i open the DLL with another application and print it to xps or printer, it's unchecked.

The checkbox is in a view and when i click on a button, the view is added to an fixedpage and this is sended to the printer with printdialog. There is nothing special in code.

Code to create fixedpage

// select printer and get printer settings
PrintDialog pd = new PrintDialog();
if (pd.ShowDialog(appView) != true) return;

// create a document
FixedDocument document = new FixedDocument();
document.DocumentPaginator.PageSize = new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight);

// create pages
FixedPage fixedPage = new FixedPage();
fixedPage.Width = document.DocumentPaginator.PageSize.Width;
fixedPage.Height = document.DocumentPaginator.PageSize.Height;

IPageViewModel pageModel = _applicationViewModel.CurrentPageViewModel;
UserControl pageView = this.GetView(pageModel);

// Add Viewmodel to Page 1
pageView.DataContext = pageModel;
pageView.Width = fixedPage.Width - 10;
pageView.Height = fixedPage.Height - 10;
pageView.Margin = new Thickness(60, 0, 10, 10);
fixedPage.Children.Add(pageView);

// add the pages to the document
PageContent overviewContent = new PageContent();
((IAddChild)overviewContent).AddChild(fixedPage);
document.Pages.Add(overviewContent);

/// and print
pd.PrintDocument(document.DocumentPaginator, "Document");

Thanks, Xander

user2499088
  • 625
  • 1
  • 6
  • 12
  • 2
    Please add a small but working example showing your problem. – Silvermind Dec 17 '13 at 09:20
  • I would like to, either see more code, or a more detailed question. I left my crystal ball at home. – Silvermind Dec 17 '13 at 09:54
  • I added some code, and description. There is nothing more than this. – user2499088 Dec 17 '13 at 10:08
  • have you applied any style to your checkbox? – Neel Bhasin Dec 17 '13 at 11:32
  • No, it's just an simple checkbox with only the IsChecked property. – user2499088 Dec 17 '13 at 12:28
  • *How is this possible??* Easy. What you think you're doing you are NOT doing. Instead of calling `GetView(pageModel)`, simply print a `CheckBox` after setting `IsChecked` to true. You will then see it checked in the xps document. Next, put a breakpoint where you call `GetView` and examine the object model to find the `CheckBox`. You will see that the view isn't what you expected, and that you are, e.g., referencing an old version of a dll. –  Dec 17 '13 at 15:28
  • I don't use an old DLL. So I think GetView(pageModel) isn't the problem, because it works in VS12 but not when started from an external program. – user2499088 Dec 18 '13 at 13:02
  • @Will Actually, in this case it's a.NET buggy behavior. The checkbox state does not get reflected on printout, unless you make your checkbox Disabled. Just reproduced it myself, thanks to the following question: http://stackoverflow.com/questions/13367557/wpf-checkbox-state-does-not-update-in-fixedpage – Eternal21 Feb 26 '15 at 18:05
  • Well, throw that in an answer so OP can select it as correct. Also, somebody (with the issue) should open a connect with MS if you have a reproable demo. –  Feb 26 '15 at 19:24

1 Answers1

0

In this case it's a.NET buggy behavior. The checkbox state does not get reflected on printout, unless you make your checkbox Disabled. Same thing happens for RadioButtons. Just reproduced it myself, thanks to the following question:

WPF Checkbox state does not update in FixedPage

Community
  • 1
  • 1
Eternal21
  • 4,190
  • 2
  • 48
  • 63