程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> WPF中自定義漂亮的進度條

WPF中自定義漂亮的進度條

編輯:關於.NET

wpf中自帶的進度條是這個樣子德。

在2003中這個進度條的樣子就會變得非常難看。

在wpf中您可以自己制作任意樣式的進度條。如下圖:

UserControl.xaml

用戶控件

<Grid x:Name="LayoutRoot" Background="Transparent"
               HorizontalAlignment="Center" VerticalAlignment="Center">
         <Grid.RenderTransform>
             <ScaleTransform x:Name="SpinnerScale"
                                 ScaleX="1.0" ScaleY="1.0" />
         </Grid.RenderTransform>
         <Canvas RenderTransformOrigin="0.5,0.5"
                     HorizontalAlignment="Center"
                     VerticalAlignment="Center"
                     Width="120" Height="120" >
             <Ellipse Width="21.835" Height="21.862"
                          Canvas.Left="20.1696"
                          Canvas.Top="9.76358"
                          Stretch="Fill" Fill="Orange"
                          Opacity="1.0"/>
             <Ellipse Width="21.835" Height="21.862"
                          Canvas.Left="2.86816"
                          Canvas.Top="29.9581" Stretch="Fill"
                          Fill="Black" Opacity="0.9"/>
             <Ellipse Width="21.835" Height="21.862"
                          Canvas.Left="5.03758e-006"
                          Canvas.Top="57.9341" Stretch="Fill"
                          Fill="Black" Opacity="0.8"/>
             <Ellipse Width="21.835" Height="21.862"
                          Canvas.Left="12.1203"
                          Canvas.Top="83.3163" Stretch="Fill"
                          Fill="Black" Opacity="0.7"/>
             <Ellipse Width="21.835" Height="21.862"
                          Canvas.Left="36.5459"
                          Canvas.Top="98.138" Stretch="Fill"
                          Fill="Black" Opacity="0.6"/>
             <Ellipse Width="21.835" Height="21.862"
                          Canvas.Left="64.6723"
                          Canvas.Top="96.8411" Stretch="Fill"
                          Fill="Black" Opacity="0.5"/>
             <Ellipse Width="21.835" Height="21.862"
                          Canvas.Left="87.6176"
                          Canvas.Top="81.2783" Stretch="Fill"
                          Fill="Black" Opacity="0.4"/>
             <Ellipse Width="21.835" Height="21.862"
                          Canvas.Left="98.165"
                          Canvas.Top="54.414" Stretch="Fill"
                          Fill="Black" Opacity="0.3"/>
             <Ellipse Width="21.835" Height="21.862"
                          Canvas.Left="92.9838"
                          Canvas.Top="26.9938" Stretch="Fill"
                          Fill="Black" Opacity="0.2"/>
             <Ellipse Width="21.835" Height="21.862"
                          Canvas.Left="47.2783"
                          Canvas.Top="0.5" Stretch="Fill"
                          Fill="Black" Opacity="0.1"/>
             <Canvas.RenderTransform>
                 <RotateTransform x:Name="SpinnerRotate"
                                      Angle="0" />
             </Canvas.RenderTransform>
             <Canvas.Triggers>
                 <EventTrigger RoutedEvent="ContentControl.Loaded">
                     <BeginStoryboard>
                         <Storyboard>
                             <DoubleAnimation
                                     Storyboard.TargetName
                                         ="SpinnerRotate"
                                      Storyboard.TargetProperty
                                         ="(RotateTransform.Angle)"
                                      From="0" To="360"
                                      Duration="0:0:01"
                                      RepeatBehavior="Forever" />
                         </Storyboard>
                     </BeginStoryboard>
                 </EventTrigger>
             </Canvas.Triggers>
         </Canvas>
     </Grid>

UserControl.xaml.cs

後台代碼

public UserControl1()
         {
             InitializeComponent();
             Timeline.DesiredFrameRateProperty.OverrideMetadata(
                        typeof(Timeline),
                            new FrameworkPropertyMetadata { DefaultValue = 20 });
         }

程序中添加對此用戶控件的命名空間

<Grid>
         <local:UserControl1></local:UserControl1>
     </Grid>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved