固定页面中的WPF复选框状态不会更新

固定页面中的WPF复选框状态不会更新,第1张

概述我试图基于在 WPF中用作模板的FixedPage元素导出一些数据,我似乎在更新复选框的值时遇到问题.奇怪的是我在模板中也使用了Textblocks和Textboxes,但这些更新内容没有问题. 所以…从一开始.我要导出的数据位于名为RepairStatement的类中,该类允许使用printForm函数打印到自定义xps文件. public class RepairStatement{ 我试图基于在 WPF中用作模板的FixedPage元素导出一些数据,我似乎在更新复选框的值时遇到问题.奇怪的是我在模板中也使用了Textblocks和TextBoxes,但这些更新内容没有问题.

所以…从一开始.我要导出的数据位于名为Repairstatement的类中,该类允许使用printForm函数打印到自定义xps文件.

public class Repairstatement{    // Variables    public bool hasKulanz { get; set; }    public bool hasRepair { get; set; }    public ClIEnt clIEnt { get; set; }    /// <summary>    /// Export repair statement to XPS file.     /// </summary>    /// <param name="file">output xps file</param>    public voID printForm(string file)    {        string printTemplateRepairstatementPath = "Print Templates\Repairstatement.xaml";        // define general purpose handlers to be used in browsing the print templates        fileStream fileStream;        if (!file.Exists(file))        {            fileStream newfile = file.Create(file);            newfile.Close();        }        // Check that all xaml templates exist        if (!file.Exists(printTemplateRepairstatementPath))        {            throw new ArgumentNullException(printTemplateRepairstatementPath,"Repair Statement print template is not available. Check file source");        }        Fixeddocument doc = new Fixeddocument();        // A4 Standard: 8.27 x 11.69 inch; 96 dpi        Size documentSize = new Size(96 * 8.27,96 * 11.69);        doc.documentPaginator.PageSize = documentSize;        // 1. Reparatur-Bericht        //  a. Open the filestream        try        {            fileStream = new fileStream(printTemplateRepairstatementPath,fileMode.Open);        }        catch (Exception e)        {            throw new ArgumentNullException(LoginAgent.userSerializationPath,"Repair Statement print template Could not be open due to " + e.Message);        }        //  b. Read the XAML tree        FixedPage fixedPage = XamlReader.Load(fileStream) as FixedPage;        //  c. Set the data        (fixedPage.Findname("receiptAddress") as TextBox).Text = clIEnt.receiptAddress; // Works        (fixedPage.Findname("deliveryAddress") as TextBox).Text = clIEnt.deliveryAddress;// Works        (fixedPage.Findname("hasEndorser") as CheckBox).IsChecked = true;  // Has no effect        //  d. Set the page size        fixedPage.WIDth = doc.documentPaginator.PageSize.WIDth;        fixedPage.Height = doc.documentPaginator.PageSize.Height;        // Add to document        PageContent pageContent = new PageContent();        ((IAddChild)pageContent).AddChild(fixedPage);        doc.Pages.Add(pageContent);        // Convert to XPS        Xpsdocument xpsdocument = new Xpsdocument(file,fileAccess.Write);        XpsdocumentWriter documentWriter = Xpsdocument.CreateXpsdocumentWriter(xpsdocument);        documentWriter.Write(doc);        xpsdocument.Close();    }}

我使用的xaml模板如下所示:

<FixedPage xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       name="RepairstatementFixedPage"       Background="White"       WIDth="793.92" Height="1122.24" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"><border name="bigPage" borderThickness="1" borderBrush="#FFCB9999" WIDth="793.92" Height="1122.24"         HorizontalAlignment="Center" VerticalAlignment="Center">  <border name="content" margin="96,96">    <DockPanel LastChildFill="False">        <GrID DockPanel.Dock="top" name="Title">          <GrID.ColumnDeFinitions>            <ColumnDeFinition WIDth="120" />            <ColumnDeFinition WIDth="*" />            <ColumnDeFinition WIDth="120" />          </GrID.ColumnDeFinitions>          <GrID.RowDeFinitions>            <RowDeFinition Height="*" />            <RowDeFinition Height="10" />            <RowDeFinition Height="*" />          </GrID.RowDeFinitions>            <Image GrID.Column="0" GrID.rowspan="3" WIDth="120"               Source="/Desktoplibrarian;component/Content/lib-bg.jpg"              VerticalAlignment="top" HorizontalAlignment="left" />            <TextBlock GrID.Column="1" GrID.rowspan="3" HorizontalAlignment="Center" VerticalAlignment="Bottom"               TextBlock.FontSize="23">              Reparaturbericht            </TextBlock>            <TextBlock GrID.Column="2" GrID.Row="0" GrID.rowspan="3"               VerticalAlignment="top" HorizontalAlignment="Right" name="repairNumber">              TEST            </TextBlock>        </GrID>        <border DockPanel.Dock="top" Height="20" />        <GrID DockPanel.Dock="top" name="deviceInfo">          <GrID.ColumnDeFinitions>            <ColumnDeFinition WIDth="*" />            <ColumnDeFinition WIDth="*" />          </GrID.ColumnDeFinitions>          <GrID.RowDeFinitions>            <RowDeFinition Height="*" />            <RowDeFinition Height="*" />          </GrID.RowDeFinitions>        </GrID>        <!-- ClIEnt information -->         <GroupBox DockPanel.Dock="top" header="Kundeninformationen">          <GrID margin="3">            <GrID.ColumnDeFinitions>              <ColumnDeFinition WIDth="130" />              <ColumnDeFinition WIDth="3" />              <ColumnDeFinition WIDth="110" />              <ColumnDeFinition WIDth="8" />              <ColumnDeFinition WIDth="*" />              <ColumnDeFinition WIDth="8" />              <ColumnDeFinition WIDth="*" />            </GrID.ColumnDeFinitions>            <GrID.RowDeFinitions>              <RowDeFinition Height="auto" />              <RowDeFinition Height="auto" />              <RowDeFinition Height="auto" />              <RowDeFinition Height="auto" />              <RowDeFinition Height="auto" />            </GrID.RowDeFinitions>            <!-- name -->            <TextBlock GrID.Column="0" GrID.ColumnSpan="3" GrID.Row="0" name="clIEntname"               TextBlock.FontWeight="Bold">              TEST            </TextBlock>            <!-- Phone Number -->            <TextBlock GrID.Column="0" GrID.Row="2">Telefonnummer:</TextBlock>            <TextBlock GrID.Column="2" GrID.Row="2" name="phoneNumber">TEST</TextBlock>            <!-- Auftragsnummer -->            <TextBlock GrID.Column="0" GrID.Row="3">Auftragsnummer (RMA):</TextBlock>            <TextBlock GrID.Column="2" GrID.Row="3" name="orderNumber">TEST</TextBlock>            <!-- Receipt Address -->            <TextBlock GrID.Column="4" GrID.Row="1">Rechnungsadresse:</TextBlock>              <TextBox GrID.Column="4" GrID.Row="2" GrID.rowspan="2" name="receiptAddress" borderThickness="0"                 AcceptsReturn="True" textwrapPing="Wrap">                TEST              </TextBox>            <!-- Delivery Address -->            <TextBlock GrID.Column="6" GrID.Row="1">LIEferadresse:</TextBlock>              <TextBox GrID.Column="6" GrID.Row="2" GrID.rowspan="2" name="deliveryAddress" borderThickness="0"                 AcceptsReturn="True" textwrapPing="Wrap">                TEST              </TextBox>          </GrID>        </GroupBox>        <border DockPanel.Dock="top" Height="20" />        <!-- Device information -->        <GroupBox DockPanel.Dock="top" header="Geräteinformationen">          <GrID margin="3">            <GrID.ColumnDeFinitions>              <ColumnDeFinition WIDth="90" />              <ColumnDeFinition WIDth="3" />              <ColumnDeFinition WIDth="150" />              <ColumnDeFinition WIDth="8" />              <ColumnDeFinition WIDth="*" />              <ColumnDeFinition WIDth="*" />            </GrID.ColumnDeFinitions>            <GrID.RowDeFinitions>              <RowDeFinition Height="auto" />              <RowDeFinition Height="auto" />              <RowDeFinition Height="auto" />              <RowDeFinition Height="auto" />              <RowDeFinition Height="auto" />            </GrID.RowDeFinitions>            <!-- Model -->            <TextBlock GrID.Column="0" GrID.ColumnSpan="3" GrID.Row="0" name="model" TextBlock.FontWeight="Bold">              TEST            </TextBlock>            <!-- Repair -->            <CheckBox GrID.Column="4" GrID.Row="1" name="hasRepair">Reparatur</CheckBox>            <!-- Device has endorser -->            <CheckBox GrID.Column="4" GrID.Row="2" name="hasEndorser">Endorsergerät</CheckBox>          </GrID>        </GroupBox>    </DockPanel>  </border></border>

问题出在printForm函数的这三行中:

//  c. Set the data        (fixedPage.Findname("receiptAddress") as TextBox).Text = clIEnt.receiptAddress;        (fixedPage.Findname("deliveryAddress") as TextBox).Text = clIEnt.deliveryAddress;        (fixedPage.Findname("hasEndorser") as CheckBox).IsChecked = true;

前两行正常修改文本框的内容.我也可以毫无问题地修改Textblocks的内容,但无论我尝试做什么,复选框的值都不会改变.我认为它与FixedPage或Fixeddocument有关,但我无法理解问题可能是什么.如果我在XAML中设置IsChecked =“True”,则复选框将在最终的xps文档中显示为已选中,但类似地我无法取消选中它.

任何关于可能出错的提示都将不胜感激.如果你知道有关FixedPage和Fixeddocument的好教程或信息来源,我也很想看看它们,因为到目前为止我发现的文档至少可以说是谦虚的.

谢谢!

更新:
我还在msdn论坛here上询问了这个问题,并在导出到xps之前得到了一些关于使用Measure(),Arrange和updatelayout()的提示.不幸的是,这个解决方案似乎不起作用.考虑到textblock和textBox元素的行为符合预期,我认为它本来是一个很远的镜头,我只有复选框的问题.

我决定制作一个显示错误的小项目,这样你也可以自己尝试一下.你可以找到它here.

如果你搞清楚了,请告诉我:D

解决方法 我发现了问题,我也找到了解决方案的一些开端.

显然启用的复选框不会检查导出到wpf的时间.我想开发人员在编写代码时的想法是,只能手动检查一张纸上的复选框.最不幸的是,我想以编程方式检查它们.

我也找到了解决这个问题的方法.已禁用的复选框显示为已选中且未选中.当然主要的缺点是它们都是灰色的,就像残疾复选框一样.

嗯……我想是时候弄清楚如何重新启动我的禁用复选框,看起来它们已经启用了.嗯….也许打印其中五个在彼此之上?手指交叉!

总结

以上是内存溢出为你收集整理的固定页面中的WPF复选框状态不会更新全部内容,希望文章能够帮你解决固定页面中的WPF复选框状态不会更新所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1060114.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存