Ngôn ngữ lập trình: XAML
Tác giả: Sưu tầm từ MSDN
Chức năng: Mã nguồn XAML tạo 1 ProgressBar dạng kim đồng hồ
ScreenShot:
Mã XAML:
Mã: Chọn hết
- <Window x:Class="WpfApplication1.Window1"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="ScrollBar ProgressBar" Height="300" Width="400">
- <Window.Resources>
- <ControlTemplate x:Key="templateSpeedometer" TargetType="ProgressBar">
- <ControlTemplate.Resources>
- <Style TargetType="Line">
- <Setter Property="Stroke" Value="Black"></Setter>
- <Setter Property="StrokeThickness" Value="1"></Setter>
- <Setter Property="X1" Value="-85"></Setter>
- <Setter Property="X2" Value="-95"></Setter>
- </Style>
- <Style TargetType="TextBlock">
- <Setter Property="FontSize" Value="11" />
- <Setter Property="Foreground" Value="Black" />
- </Style>
- </ControlTemplate.Resources>
- <Border Width="270" Height="120"
- BorderBrush="{TemplateBinding BorderBrush}"
- BorderThickness="{TemplateBinding BorderThickness}"
- Background="{TemplateBinding Background}">
-
- <Canvas Width="0" Height="0"
- RenderTransform="1 0 0 1 0 50" >
-
- <Rectangle Name="PART_Track" Width="180" />
- <Rectangle Name="PART_Indicator" />
-
- <Line LayoutTransform=" 1.00 0.00 -0.00 1.00 0 0" />
- <Line LayoutTransform=" 0.95 0.31 -0.31 0.95 0 0" />
- <Line LayoutTransform=" 0.81 0.59 -0.59 0.81 0 0" />
- <Line LayoutTransform=" 0.59 0.81 -0.81 0.59 0 0" />
- <Line LayoutTransform=" 0.31 0.95 -0.95 0.31 0 0" />
- <Line LayoutTransform=" 0.00 1.00 -1.00 0.00 0 0" />
- <Line LayoutTransform="-0.31 0.95 0.95 0.31 0 0" />
- <Line LayoutTransform="-0.59 0.81 0.81 0.59 0 0" />
- <Line LayoutTransform="-0.81 0.59 0.59 0.81 0 0" />
- <Line LayoutTransform="-0.95 0.31 0.31 0.95 0 0" />
- <Line LayoutTransform="-1.00 0.00 0.00 1.00 0 0" />
-
- <TextBlock Text="0%" Canvas.Left="-115" Canvas.Top="-6" />
- <TextBlock Text="20%" Canvas.Left="-104" Canvas.Top="-65" />
- <TextBlock Text="40%" Canvas.Left="-42" Canvas.Top="-105" />
- <TextBlock Text="60%" Canvas.Left="25" Canvas.Top="-105" />
- <TextBlock Text="80%" Canvas.Left="82" Canvas.Top="-65" />
- <TextBlock Text="100%" Canvas.Left="100" Canvas.Top="-6" />
-
- <Polygon Points="5 5 5 -5 -75 0"
- Stroke="Black" Fill="Red">
- <Polygon.RenderTransform>
- <RotateTransform
- Angle="{Binding ElementName=PART_Indicator,
- Path=ActualWidth}" />
- </Polygon.RenderTransform>
- </Polygon>
- </Canvas>
- </Border>
- </ControlTemplate>
- </Window.Resources>
- <StackPanel>
- <ProgressBar Minimum="0" Maximum="100" Margin="50" Template="{StaticResource templateSpeedometer}" Value="{Binding ElementName=scroll, Path=Value}"></ProgressBar>
- <ScrollBar Name="scroll" Orientation="Horizontal" Minimum="0" Maximum="100" SmallChange="1" LargeChange="10" Margin="50 0 50 0"></ScrollBar>
- </StackPanel>
- </Window>
Download mã nguồn tại đây: