c# - XPS 文档中未反射(reflect)绑定(bind)值

标签 c# wpf data-binding printing xps

我已经通过绑定(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/

相关文章:

c# - ASP.NET 动态修改控件树

c# - 如何在 ASP.NET Core 2.2 中使用 IValidateOptions 验证配置设置?

wpf - 用户控件应该有自己的 View 模型吗?

c# - 具有自定义用户控件的多阶段数据绑定(bind)

c# - 枚举整数转换异常可能吗?

c# - WPF:使用调度程序在 TextBox VS 中移动插入符号。不使用它

c# - 声明对象时可以调用类的方法吗?

c# - 如何用数据一致地更新线系列图表?

javascript - Polymer 1.0 dom-repeat 显示索引从1开始

c# - Asp.net 数据透视表