【问题标题】:Progress Bar Bind Value进度条绑定值
【发布时间】:2011-08-26 19:29:12
【问题描述】:

已修复。必须同时绑定最大值和值,它起作用了。在测试中,我将两者都绑定到 Int32(没有测试将两者都绑定到双精度)。微软我认为这是一个错误。

   <ProgressBar Grid.Row="8" Grid.Column="0" HorizontalContentAlignment="Stretch" Height="20" Maximum="{Binding Path=DF.WFBatchFolderStatus.DocCount}" Value="{Binding Path=DF.WFBatchFolderStatus.DocCountComplete}" PresentationTraceSources.TraceLevel="High" />

什么是协议。如果我回答自己的问题,我应该删除问题吗?

当我尝试为进度条绑定值时出现错误。 XamlParseException '设置属性 'System.Windows.Controls.Primitives.RangeBase.Value' 引发异常。 Grid.Row 8 失败,Grid.Row 9 失败。当我输入固定值(Grid.Row 6 和 Grid.Row 7)时,它可以工作。我可以在 TextBlock (Grid.Row 5) 中检索我想要绑定的值。我尝试绑定到 Double 和 Int 32。根据文档,Minimum、Maximum 和 Value 是双倍的。它失败的计算值是 2(并且它在其他值上失败)。在此先感谢,我会标记答案。

    <TextBlock Grid.Row="5" Grid.Column="0" HorizontalAlignment="Left" Text="{Binding Path=DF.WFBatchFolderStatus.DocPctComplete, StringFormat='Document Pct Count:  {0}'}" PresentationTraceSources.TraceLevel="High" />
    <ProgressBar Grid.Row="6" Grid.Column="0" HorizontalContentAlignment="Stretch" Height="20" Minimum="0" Maximum="100" Value="40" />
    <ProgressBar Grid.Row="7" Grid.Column="0" HorizontalContentAlignment="Stretch" Height="20" Minimum="0E0" Maximum="100E0" Value="60E0" />
    <ProgressBar Grid.Row="8" Grid.Column="0" HorizontalContentAlignment="Stretch" Height="20" Minimum="0" Maximum="100" Value="{Binding Path=DF.WFBatchFolderStatus.DocPctCompleteInt}" PresentationTraceSources.TraceLevel="High" />
    <ProgressBar Grid.Row="9" Grid.Column="0" HorizontalContentAlignment="Stretch" Height="20" Minimum="0E0" Maximum="100E0" Value="{Binding Path=DF.WFBatchFolderStatus.DocPctComplete}" PresentationTraceSources.TraceLevel="High" /> 

    public Double DocPctComplete
    {
        get
        {
            if (BatchFolderStatus == enumBatchFolderStatus.Waiting) return 0;
            if (BatchFolderStatus == enumBatchFolderStatus.WaitQC) return 0;
            if (BatchFolderStatus == enumBatchFolderStatus.Complete) return 100;
            if (DocCount < 1) return 0;
            if (DocCountComplete < 1) return 0;
            double docPctComplete = (Convert.ToDouble(DocCountComplete) / Convert.ToDouble(DocCount)) * 100E0;
            Debug.WriteLine("docPctComplete " + docPctComplete.ToString());
            return docPctComplete;
        }
    }
    public Int32 DocPctCompleteInt
    {
        get
        {
            if (BatchFolderStatus == enumBatchFolderStatus.Waiting) return 0;
            if (BatchFolderStatus == enumBatchFolderStatus.WaitQC) return 0;
            if (BatchFolderStatus == enumBatchFolderStatus.Complete) return 100;
            if (DocCount < 1) return 0;
            if (DocCountComplete < 1) return 0;
            double docPctComplete = (Convert.ToDouble(DocCountComplete) / Convert.ToDouble(DocCount)) * 100E0;
            Debug.WriteLine("docPctComplete " + docPctComplete.ToString());
            Int32 docPctCompleteInt = Convert.ToInt32(docPctComplete);
            Debug.WriteLine("docPctCompleteInt " + docPctCompleteInt.ToString());
            return docPctCompleteInt;
        }
    }

【问题讨论】:

  • 协议是回答您自己的问题并将其标记为已接受,这样如果有人正在寻找类似问题的答案,他将被重定向到这个问题。

标签: wpf binding progress-bar


【解决方案1】:

已修复。必须同时绑定最大值和值,它起作用了。在测试中,我将两者都绑定到 Int32(没有测试将两者都绑定到双精度)。微软我认为这是一个错误。如果最大值是 XAML 但绑定中的值失败(或者对我来说失败了)。

【讨论】:

    【解决方案2】:

    是否期望从 0.0 到 1.0 的 Double?

    不应该,但这能解决问题吗?

    另外,我通常在这样的代码中指定 Double 常量:0.0D、1.0D、100.0D

    【讨论】:

    • 我试着去掉 100 给它一个 0.02 的值,但这并没有帮助。我以为 D 代表十进制(不是双精度),但我会尝试的。当我尝试输入 Maximum="100D" 时出现语法错误。需要 100、100E 或 100E0。
    • 在文档中不是很明显。不过我终于找到了:msdn.microsoft.com/en-us/library/bfft1t3c.aspx
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2020-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 1970-01-01
    相关资源
    最近更新 更多