用WPF如何制作QQ播放器那个音乐进度条(如下图:)
发布网友
发布时间:2022-04-22 12:45
我来回答
共2个回答
热心网友
时间:2022-07-12 07:19
你可以尝试一下用Slider
类似:
<Slider x:Name="idSlider" Maximum="600" Minimum="1" TickFrequency="1" Margin="65, 0, 40, 0" Template="{StaticResource SliderStyleTemplate}"/>
定义Template相关:
<Style x:Key="DecreaseRepeatButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Border Margin="0,18" Background="#C3C3C3">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Height" Value="40"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="SnapsToDevicePixels" Value="true" />
</Style>
<Style x:Key="IncreaseRepeatButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Border Margin="0,18" Background="Black">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="Height" Value="40"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Focusable" Value="False"/>
</Style>
<ControlTemplate x:Key="SliderStyleTemplate" TargetType="{x:Type Slider}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="40"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Track x:Name="PART_Track" Grid.Row="1" HorizontalAlignment="Stretch">
<Track.IncreaseRepeatButton>
<RepeatButton Style="{StaticResource IncreaseRepeatButtonStyle}"
Command="Slider.IncreaseLarge"/>
</Track.IncreaseRepeatButton>
<Track.DecreaseRepeatButton>
<RepeatButton Style="{StaticResource DecreaseRepeatButtonStyle}"
Command="Slider.DecreaseLarge"/>
</Track.DecreaseRepeatButton>
</Track>
</Grid>
</ControlTemplate>
思路:准备播放音乐时,以秒为单位提取时长,将时长赋值给Slider的Maximum,音乐播放过程更新Slider的Value值,这样应该可以实现。
热心网友
时间:2022-07-12 07:19
你可以用 Blend 试试