本篇文章為大家展示了WPF中怎么自定義ProgressBar滾動條樣式,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
一、前言
滾動條一般用于加載進度,我們在看視頻的時候或者在瀏覽網頁的時候經常能看到加載進度的頁面。在程序開發中,默認的進度加載樣式可能跟程序風格不太一樣,或者加載進度的時候需要更改一下加載的樣式。這個時候就需要通過修改ProgressBar的樣式來實現。
二、ProgressBar的基本樣式
ProgressBar的基本樣式很簡單:
<Style TargetType="{x:Type ProgressBar}"> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="SnapsToDevicePixels" Value="True"/> <Setter Property="Height" Value="15"/> <Setter Property="Background" Value="#6fae5f"/> <Setter Property="FontSize" Value="10"/> <Setter Property="Padding" Value="5,0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ProgressBar}"> <Grid Background="#00000000"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Determinate"/> <VisualState x:Name="Indeterminate"> <Storyboard RepeatBehavior="Forever"> <PointAnimationUsingKeyFrames Storyboard.TargetName="Animation" Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)"> <EasingPointKeyFrame KeyTime="0:0:0" Value="0.5,0.5"/> <EasingPointKeyFrame KeyTime="0:0:1.5" Value="1.95,0.5"/> <EasingPointKeyFrame KeyTime="0:0:3" Value="0.5,0.5"/> </PointAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid Height="{TemplateBinding Height}"> <Border Background="#000000" CornerRadius="7.5" Opacity="0.05"/> <Border BorderBrush="#000000" BorderThickness="1" CornerRadius="7.5" Opacity="0.1"/> <Grid Margin="{TemplateBinding BorderThickness}"> <Border x:Name="PART_Track"/> <Grid x:Name="PART_Indicator" ClipToBounds="True" HorizontalAlignment="Left" > <Grid.ColumnDefinitions> <ColumnDefinition x:Name="width2"/> <ColumnDefinition x:Name="width3" Width="0"/> </Grid.ColumnDefinitions> <Grid x:Name="Animation" RenderTransformOrigin="0.5,0.5"> <Grid.RenderTransform> <TransformGroup> <ScaleTransform ScaleY="-1" ScaleX="1"/> <SkewTransform AngleY="0" AngleX="0"/> <RotateTransform Angle="180"/> <TranslateTransform/> </TransformGroup> </Grid.RenderTransform> <Border Background="{TemplateBinding Background}" CornerRadius="7.5"> <Viewbox HorizontalAlignment="Left" StretchDirection="DownOnly" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="True"> <TextBlock Foreground="#ffffff" SnapsToDevicePixels="True" FontSize="{TemplateBinding FontSize}" VerticalAlignment="Center" Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Value,StringFormat={}{0}%}" RenderTransformOrigin="0.5,0.5"> <TextBlock.RenderTransform> <TransformGroup> <ScaleTransform ScaleY="1" ScaleX="-1"/> <SkewTransform AngleY="0" AngleX="0"/> <RotateTransform Angle="0"/> <TranslateTransform/> </TransformGroup> </TextBlock.RenderTransform> </TextBlock> </Viewbox> </Border> <Border BorderBrush="#000000" BorderThickness="1" CornerRadius="7.5" Opacity="0.1"/> </Grid> </Grid> </Grid> </Grid> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Background" Value="#c5c5c5"/> </Trigger> <Trigger Property="IsIndeterminate" Value="true"> <Setter TargetName="width2" Property="Width" Value="0.25*"/> <Setter TargetName="width3" Property="Width" Value="0.725*"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
引用示例:
<ProgressBar Height="15" Width="150" Value="40" Margin="10"/>
上述內容就是WPF中怎么自定義ProgressBar滾動條樣式,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注創新互聯行業資訊頻道。
當前標題:WPF中怎么自定義ProgressBar滾動條樣式-創新互聯
本文鏈接:http://www.yijiale78.com/article48/ddoiep.html
成都網站建設公司_創新互聯,為您提供關鍵詞優化、App開發、云服務器、全網營銷推廣、企業網站制作、電子商務
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯