最近做播放器相关的程序,搞的头皮发麻,真是学艺不精啊这不,用Slider改造出来的一个音量控制控件,搞了一下午才弄出来,唉.
啥也不说了,先看看Demo效果吧
提示就是Valuer 值, 可以看到,Value有时会显示很长呢.原因是double类型保留位数没有做限制,当IsMoveToPointEnabled=”True”时,Value有时变成无限循环,保留一下位数就行啦
下面当然是上代码了,除了代码我什么都没有….
<Window x:Class="wpf_test.FullScreenTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:wpf_test"
mc:Ignorable="d"
WindowStyle="None"
Title="FullScreenTest" Height="450" Width="800">
<Window.Resources>
<Style x:Key="RepeatButtonTransparent" TargetType="{x:Type RepeatButton}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Rectangle Fill="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ControlTemplate x:Key="SliderHorizontal" TargetType="{x:Type Slider}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border x:Name="TrackBackground" BorderBrush="Blue" BorderThickness="1" Background="Yellow" Height="4.0" Margin="5,0" Grid.Row="1" VerticalAlignment="center">
<Canvas Margin="-6,-1">
<Rectangle x:Name="PART_SelectionRange" Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" Height="4.0" Visibility="Hidden"/>
</Canvas>
</Border>
<Track x:Name="PART_Track" Grid.Row="1">
<Track.DecreaseRepeatButton>
<RepeatButton Height="4" Background="#07A2FD" Command="{x:Static Slider.DecreaseLarge}" Style="{StaticResource RepeatButtonTransparent}"/>
</Track.DecreaseRepeatButton>
<Track.IncreaseRepeatButton>
<RepeatButton Height="4" Background="#C1C1C1" Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource RepeatButtonTransparent}"/>
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb x:Name="Thumb" Focusable="False" Visibility="Hidden" OverridesDefaultStyle="True" VerticalAlignment="Center" />
</Track.Thumb>
</Track>
</Grid>
</Border>
</ControlTemplate>
<Style x:Key="SliderStyle1" TargetType="{x:Type Slider}">
<Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Foreground" Value="#FFE5E5E5"/>
<Setter Property="Template" Value="{StaticResource SliderHorizontal}"/>
</Style>
</Window.Resources>
<DockPanel>
<Grid Background="Red" Height="35" DockPanel.Dock="Top"></Grid>
<Grid Background="LightCoral" Width="180" DockPanel.Dock="Right"></Grid>
<Grid Background="White" Margin="50" >
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Slider Margin="10" HorizontalAlignment="Right" Value="{Binding VideoVolume1}" Width="84"
IsMoveToPointEnabled="True" Cursor="Hand" ToolTip="{Binding Path=Value,RelativeSource={RelativeSource self}}"
VerticalAlignment="Top" Style="{DynamicResource SliderStyle1}" />
<Slider Margin="10" HorizontalAlignment="Right" Cursor="Hand" ToolTip="{Binding Path=Value,RelativeSource={RelativeSource self}}" Width="84"
VerticalAlignment="Top" Style="{DynamicResource SliderStyle1}" />
</StackPanel>
</Grid>
</DockPanel>
</Window>
后台无代码,样式不多,也就56十行,算了,今天就这样了.拜了个拜
写代码真是有趣(强行有趣?),虽然很累,但是很开心呢,做出点什么也会很开心.
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容