打印时始终取消选中WPF复选框

本文关键字:WPF 复选框 取消 打印 | 更新日期: 2024-10-22 09:53:09

我有一个WPF库项目,当我在visual studio中运行它时,它运行得很完美,打印功能也正常工作,但当我从另一个应用程序打开项目并打印它时,复选框总是空的。

我尝试了不绑定和绑定,但复选框总是空的。

这怎么可能??

复选框如下:

<CheckBoc IsChecked="true"/>

当我从visualstudio打印它时,它被选中了,但当我用另一个应用程序打开DLL并将其打印到xps或打印机时,它没有被选中。

复选框在一个视图中,当我单击一个按钮时,该视图会添加到一个固定的页面中,并通过打印对话框发送到打印机。代码中没有什么特别之处。

创建固定页面的代码

// 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");

谢谢,Xander

打印时始终取消选中WPF复选框

在这种情况下,这是.NET错误行为。复选框状态不会反映在打印输出中,除非您将复选框设置为"禁用"。RadioButtons也是如此。由于以下问题,我自己刚刚复制了它:

WPF复选框状态未在FixedPage 中更新