如何在滑块上画线或其他东西?

发布于 2024-10-16 20:09:17 字数 352 浏览 7 评论 0原文

我将为我自己的播放器设计一个搜索栏。我已经在使用滑块了。

场景:当用户点击按钮A时,在搜索栏中,将绘制一条线并一直持续到用户点击按钮B。查看图片以更好地理解! ;)

图片 http://efreephoto.com/pictures/11182763364d5141df3d8d8.png

如何我可以在滑块上画红线吗?

I'm going to design a Seek bar for my own player. I already using Slider.

Scenario: When user clicks on button A, in seek bar, a line will be drawn and continues until user clicks on button B. Check out the image to understand better! ;)

Image http://efreephoto.com/pictures/11182763364d5141df3d8d8.png

How can i just draw that red line on Slider?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-10-23 20:09:17

我相信有两种解决方案。

  • 创建自定义模板(或基于现有模板)创建您自己的滑块布局。我相信您必须从 Slider 进行扩展,才能添加额外的依赖属性来存储要绘制的线条的信息。
  • 使用装饰器覆盖现有的滑块。

希望这能引导您走向正确的方向。

I believe there are two solutions.

  • Create a custom template (or base it on the existing one) to create your own slider layout. I believe you will have to extend from Slider in order to add extra dependency properties to store information for the line to draw.
  • Use an adorner to overlay over the existing slider.

Hopefully this will guide you in the right direction.

兮颜 2024-10-23 20:09:17

我认为最好的方法是使用自定义模板。

请参阅此处了解更多信息 http://msdn.microsoft.com/en-us/library /aa970773.aspx

您可以在此处下载默认控件模板
http://code.msdn.microsoft.com /Project/Download/FileDownload.aspx?ProjectName=wpfsamples&DownloadId=7741

然后您应该将默认值调整为您想要的任何内容。从上面的链接查看 slider.xaml 文件并将以下部分更新为您喜欢的内容。

<ControlTemplate x:Key="HorizontalSlider" TargetType="{x:Type Slider}">
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto" MinHeight="{TemplateBinding Slider.MinHeight}"/>
        <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>
      <TickBar 
        Name="TopTick"
        SnapsToDevicePixels="True" 
        Placement="Top"
        Fill="{StaticResource GlyphBrush}"
        Height="4"
        Visibility="Collapsed" />
      <Border 
        Name="TrackBackground"
        Margin="0"
        CornerRadius="2" 
        Height="4"
        Grid.Row="1"
        Background="{StaticResource LightBrush}" 
        BorderBrush="{StaticResource NormalBorderBrush}"
        BorderThickness="1" />
      <Track Grid.Row="1" Name="PART_Track">
        <Track.DecreaseRepeatButton>
          <RepeatButton 
            Style="{StaticResource SliderButtonStyle}"
            Command="Slider.DecreaseLarge" />
        </Track.DecreaseRepeatButton>
        <Track.Thumb>
          <Thumb Style="{StaticResource SliderThumbStyle}" />
        </Track.Thumb>
        <Track.IncreaseRepeatButton>
          <RepeatButton 
            Style="{StaticResource SliderButtonStyle}"
            Command="Slider.IncreaseLarge" />
        </Track.IncreaseRepeatButton>
      </Track>
      <TickBar 
        Name="BottomTick"
        SnapsToDevicePixels="True" 
        Grid.Row="2"
        Fill="{TemplateBinding Foreground}"
        Placement="Bottom"
        Height="4"
        Visibility="Collapsed" />
    </Grid>

The best way to go I think is to use a custom template.

See here for more http://msdn.microsoft.com/en-us/library/aa970773.aspx

You can download the default control templates here
http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wpfsamples&DownloadId=7741

Then you should adapt the default to whatever you want. From the link above have a look at the slider.xaml file and update the following section to whatever you like.

<ControlTemplate x:Key="HorizontalSlider" TargetType="{x:Type Slider}">
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto" MinHeight="{TemplateBinding Slider.MinHeight}"/>
        <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>
      <TickBar 
        Name="TopTick"
        SnapsToDevicePixels="True" 
        Placement="Top"
        Fill="{StaticResource GlyphBrush}"
        Height="4"
        Visibility="Collapsed" />
      <Border 
        Name="TrackBackground"
        Margin="0"
        CornerRadius="2" 
        Height="4"
        Grid.Row="1"
        Background="{StaticResource LightBrush}" 
        BorderBrush="{StaticResource NormalBorderBrush}"
        BorderThickness="1" />
      <Track Grid.Row="1" Name="PART_Track">
        <Track.DecreaseRepeatButton>
          <RepeatButton 
            Style="{StaticResource SliderButtonStyle}"
            Command="Slider.DecreaseLarge" />
        </Track.DecreaseRepeatButton>
        <Track.Thumb>
          <Thumb Style="{StaticResource SliderThumbStyle}" />
        </Track.Thumb>
        <Track.IncreaseRepeatButton>
          <RepeatButton 
            Style="{StaticResource SliderButtonStyle}"
            Command="Slider.IncreaseLarge" />
        </Track.IncreaseRepeatButton>
      </Track>
      <TickBar 
        Name="BottomTick"
        SnapsToDevicePixels="True" 
        Grid.Row="2"
        Fill="{TemplateBinding Foreground}"
        Placement="Bottom"
        Height="4"
        Visibility="Collapsed" />
    </Grid>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文