【发布时间】:2018-08-26 04:33:26
【问题描述】:
如何根据列表框值或组合框值移动进度条值(我正在使用进度条模拟汽车 mph 圆形仪表)?我用一个矩形做针。
我可以使用滚动条(滚动条的值使指针移动)来实现,这是我将展示的代码。 Instead of the value of the scroll bar i want to be able to have various speeds set in a listbox, combobox and when selected the progress bar / rectangle will move to that value.
这个可以吗?
我只会显示我认为您需要查看的代码.. 这是我正在谈论的图片:
<Window.Resources>
<ControlTemplate x:Key="templateSpeedometer"
TargetType="ProgressBar">
<ControlTemplate.Resources>
<Style TargetType="Line">
</Style>
</ControlTemplate.Resources>
<Canvas Width="0" Height="0"
RenderTransform="1 0 0 1 0 50" Background="#FFF50D0D">
<Rectangle Name="PART_Track" Width="180" />
<Rectangle Fill="Black" Name="PART_Indicator" />
<Polygon Points="5 2 5 -5 -75 0"
Stroke="Black" Fill="Gold">
<Polygon.RenderTransform>
<RotateTransform
Angle="{Binding ElementName=PART_Indicator,
Path=ActualWidth}" />
</Polygon.RenderTransform>
</Polygon>
</Canvas>
</Border>
</ControlTemplate>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<StackPanel>
<Grid Height="216" Name="grid1" Width="612">
<ScrollBar Name="scroll" Orientation="Horizontal" Minimum="0" Maximum="100" SmallChange="1" LargeChange="10" Margin="8,235,4,-36" />
<Border Background="#FF5EB6D8" CornerRadius="25" Height="247" VerticalAlignment="Top" Margin="13,5,27,0">
<ProgressBar Background="#FFD6E1E5" Margin="4,8,0,112" Maximum="100" Minimum="0" Template="{StaticResource templateSpeedometer}" Value="{Binding ElementName=scroll, Path=Value}" BorderBrush="#FF5EB6D8" OpacityMask="White" HorizontalAlignment="Left" Width="281" BorderThickness="5,1,1,1" Orientation="Vertical"/>
</Border>
【问题讨论】: