一、前言
創(chuàng)新互聯(lián)是一家專注于做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)與策劃設(shè)計(jì),武義網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:武義等地區(qū)。武義做網(wǎng)站價(jià)格咨詢:028-86922220
滾動條一般用于加載進(jìn)度,我們在看視頻的時(shí)候或者在瀏覽網(wǎng)頁的時(shí)候經(jīng)常能看到加載進(jìn)度的頁面。在程序開發(fā)中,默認(rèn)的進(jìn)度加載樣式可能跟程序風(fēng)格不太一樣,或者加載進(jìn)度的時(shí)候需要更改一下加載的樣式。這個(gè)時(shí)候就需要通過修改ProgressBar的樣式來實(shí)現(xiàn)。
二、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"/>
顯示效果:
所有代碼已經(jīng)上傳到github:https://github.com/cmfGit/WpfDemo.git
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對創(chuàng)新互聯(lián)的支持。
文章標(biāo)題:WPF如何自定義ProgressBar滾動條樣式
網(wǎng)頁網(wǎng)址:http://jinyejixie.com/article2/ghoeic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、網(wǎng)站策劃、網(wǎng)站設(shè)計(jì)公司、虛擬主機(jī)、用戶體驗(yàn)、營銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)