在WPF按钮中显示点点点进度

时间:2022-07-23 16:54:40

I found quite a few examples for showing progress where the progress bars and wheels are used however; I could find only one javascript example to show an ellipsis (dot-dot-dot) to refer progress hence I thought of asking this question. My app is not very complex - it only has a few check-boxes and one button. Recently my team requested for an enhancement and want to keep it simple as well.

我找到了一些例子来说明进度条和*是如何使用的;我只能找到一个javascript示例来显示一个省略号(dot-dot-dot -dot)来引用进度,因此我想提出这个问题。我的应用不是很复杂——它只有几个复选框和一个按钮。最近,我的团队要求提高,并希望保持简单。

There is a button named 'GO' that the user clicks after configuring the required settings. The code behind it is also really straightforward - it disables the button after the click event and call's a standalone exe using ProcessStartInfo that performs three actions 'reconcle', 'post' and 'publish'. I use the WaitForExist() method to re-enable the button.

有一个名为“GO”的按钮,用户在配置所需的设置后单击该按钮。它背后的代码也非常简单——它在单击事件后禁用按钮,并使用ProcessStartInfo命令调用一个独立的exe,该命令执行三个动作“reconcle”、“post”和“publish”。我使用WaitForExist()方法重新启用按钮。

I was requested by my team to show the 'current process' on the button. They simply want the button text to show Reconciling. Reconciling.. Reconciling... (at regular intervals say, 1 sec) followed by Posting and Publishing in a similar fashion.

我的团队要求我在按钮上显示“当前进程”。他们只是希望按钮文本显示和解。协调. .协调……(每隔一段时间,比如1秒)然后以类似的方式发布和发布。

It would be nice to know the most appropriate way to achieve this. Thanks in advance.

如果知道最合适的方法来实现这个目标,那就太好了。提前谢谢。

1 个解决方案

#1


10  

The simplest way of doing that is using an ObjectAnimationUsingKeyFrames. Set the TargetProperty on the Content and set the Value of each DiscreteObjectKeyFrame to Reconciling. Reconciling.. Reconciling....

最简单的方法是使用objectanimationusingkeyframe。在内容上设置TargetProperty,并设置每个离散objectkeyframe的值以进行协调。协调. .协调....

Example for a ControlTemplate with a ContentPresenter named PART_Content:

一个名为PART_Content的ContentPresenter的ControlTemplate的示例:

<ControlTemplate.Triggers>
    <Trigger Property="IsEnabled" Value="False">
        <Trigger.EnterActions>
            <BeginStoryboard>
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Content" Storyboard.TargetProperty="Content" Duration="00:00:00.8" RepeatBehavior="Forever">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00.0" Value="Loading"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:00.2" Value="Loading."/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:00.4" Value="Loading.."/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:00.6" Value="Loading..."/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </Trigger.EnterActions>
    </Trigger>
</ControlTemplate.Triggers>

#1


10  

The simplest way of doing that is using an ObjectAnimationUsingKeyFrames. Set the TargetProperty on the Content and set the Value of each DiscreteObjectKeyFrame to Reconciling. Reconciling.. Reconciling....

最简单的方法是使用objectanimationusingkeyframe。在内容上设置TargetProperty,并设置每个离散objectkeyframe的值以进行协调。协调. .协调....

Example for a ControlTemplate with a ContentPresenter named PART_Content:

一个名为PART_Content的ContentPresenter的ControlTemplate的示例:

<ControlTemplate.Triggers>
    <Trigger Property="IsEnabled" Value="False">
        <Trigger.EnterActions>
            <BeginStoryboard>
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Content" Storyboard.TargetProperty="Content" Duration="00:00:00.8" RepeatBehavior="Forever">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00.0" Value="Loading"/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:00.2" Value="Loading."/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:00.4" Value="Loading.."/>
                        <DiscreteObjectKeyFrame KeyTime="00:00:00.6" Value="Loading..."/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </Trigger.EnterActions>
    </Trigger>
</ControlTemplate.Triggers>