进度栏在WPF中不起作用 [英] Progress Bar not working in WPF

查看:63
本文介绍了进度栏在WPF中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在WPF应用程序中使用了进度条.在加载网格值之前显示进度条.加载后,网格进度栏设置为不可见.以下代码已使用.

Hi All,

Have used progress bar in WPF application. Show the progress bar when before load the grid values. After load the grid progress bar set to invisible. The below code have used.

<pre lang="xml"><Grid><br />
        <ProgressBar Margin="10,10,0,13" Name="PBar" HorizontalAlignment="Left" Foreground="#FFB9C3D5" IsIndeterminate="True"<br />
                 VerticalAlignment="Top" Width="300" Height="30" Value="20" FlowDirection="LeftToRight" ContextMenuOpening="PBar_ContextMenuOpening"><br />
            <ProgressBar.Triggers><br />
                <EventTrigger RoutedEvent="Window.Loaded"><br />
                    <BeginStoryboard><br />
                        <Storyboard><br />
                            <DoubleAnimation Storyboard.TargetName="PBar" Storyboard.TargetProperty="Value" From="0" To="100" Duration="0:0:0" /><br />
                        </Storyboard><br />
                    </BeginStoryboard><br />
                </EventTrigger><br />
            </ProgressBar.Triggers><br />
        </ProgressBar></pre><br />



在设计页面中,进度栏已设置为动画.但是运行应用程序时进度栏没有动画.仅显示进度条.

请给我解决方案.

在此先感谢.
问候,
Maha



In design page progress bar was animated. But progress bar was not animated when run the application. Only show the progress bar.

Please give me the solution.

Thanks in Advance.
Regards,
Maha

推荐答案

<StatusBar Name="sbar"

           VerticalAlignment="Bottom" Background="Beige" >

  <StatusBarItem>
    <TextBlock>Downloading File</TextBlock>
  </StatusBarItem>
  <StatusBarItem>
    <ProgressBar Width="100" Height="20"

                 Name="progressBar1">
      <ProgressBar.Triggers>
        <EventTrigger RoutedEvent="ProgressBar.Loaded">
          <BeginStoryboard>
            <Storyboard>
              <DoubleAnimation

                Storyboard.TargetName="progressBar1"

                Storyboard.TargetProperty="Value"

                From="0" To="100" Duration="0:0:5"  />
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </ProgressBar.Triggers>
    </ProgressBar>
  </StatusBarItem>
  <Separator/>
  <StatusBarItem>
    <TextBlock>Online</TextBlock>
  </StatusBarItem>
  <StatusBarItem HorizontalAlignment="Right">
    <Image Source="images\help.bmp" Width="16" Height="16"/>
  </StatusBarItem>
</StatusBar>



C#(后面的代码)



C# (code behind)

ProgressBar progbar = new ProgressBar();
progbar.IsIndeterminate = false;
progbar.Orientation = Orientation.Horizontal;
progbar.Width = 150;
progbar.Height = 15;
Duration duration = new Duration(TimeSpan.FromSeconds(10));
DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);


有关更多详细信息,请参见链接


For more details see this link


这篇关于进度栏在WPF中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆