我已经通过绑定(bind)更改了基于比例值的模板(按钮)填充颜色。此绑定(bind)值未反射(reflect)在 XPS 文档中。请在下面找到模板和XPS Document序列化代码。
问题: 未反射(reflect)绑定(bind)值(级别属性)。因此缩放比例未更改。因为,我已根据级别值更新了 scaley 值。
Xaml Code : based on the level value fill color will change.
<Canvas.Clip>
<RectangleGeometry Rect="0,2.5,100,100">
<RectangleGeometry.Transform>
<ScaleTransform ScaleX="1" ScaleY="{Binding Level}" CenterX="0" CenterY="97.5" />
</RectangleGeometry.Transform>
</RectangleGeometry>
</Canvas.Clip>
//XPS Document Code.
//Set up the WPF Control to be Saved
Canvas controlToPrint= new Canvas();
//canv is the instance of my canvas containing button.
controlToPrint = canv;
canv = null;
FixedDocument fixedDoc = new FixedDocument();
PageContent pageContent = new PageContent();
FixedPage fixedPage = new FixedPage();
//Create first page of document
fixedPage.Children.Add(controlToPrint);
((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage);
var size = fixedDoc.DocumentPaginator.PageSize;
pageContent.Measure(size);
pageContent.Arrange(new Rect(new Point(), size));
pageContent.UpdateLayout();
fixedDoc.Pages.Add(pageContent);
// Configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "MyReport"; // Default file name
dlg.DefaultExt = ".xps"; // Default file extension
dlg.Filter = "XPS Documents (.xps)|*.xps"; // Filter files by extension
// Show save file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
// Save document
string filename = dlg.FileName;
FixedDocument doc = fixedDoc;
XpsDocument xpsd = new XpsDocument(filename, FileAccess.ReadWrite);
System.Windows.Xps.XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
xw.Write(doc);
xpsd.Close();
}
请建议我如何实现这一点?
注意:
我可以在使用触发器时实现这一点。但是,我不应该使用触发器。
谢谢,
兰吉萨。
最佳答案
我有一个类似的问题,我通过在调用 InitializeComponent() 之前定义 DataContext 来解决
public PrintingView(ReportViewModel reportViewModel)
{
DataContext = _viewModel;
InitializeComponent();
}
关于c# - XPS 文档中未反射(reflect)绑定(bind)值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56983278/