WPF仪表盘控件

WPF仪表盘控件
后台代码倒是不多,关键在于xaml画表盘
先上效果图:
效果图

<UserControl x:Class="CLInstrument.InstrumentControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DesignHeight="350" d:DesignWidth="300" SnapsToDevicePixels="True">
    <UserControl.Resources>
        <SolidColorBrush x:Key="pathMain" Color="Gray" ></SolidColorBrush>
        <SolidColorBrush x:Key="pathSub" Color="#FFB4A193" ></SolidColorBrush>
        <SolidColorBrush x:Key="pointerColor" Color="Black"></SolidColorBrush>
        <SolidColorBrush x:Key="bottomSpaceColor" Color="SkyBlue"></SolidColorBrush>
        <SolidColorBrush x:Key="lowColor" Color="YellowGreen"></SolidColorBrush>
        <SolidColorBrush x:Key="normalColor" Color="Yellow"></SolidColorBrush>
        <SolidColorBrush x:Key="hightColor" Color="Red"></SolidColorBrush>
        <SolidColorBrush x:Key="mainColor" Color="LightBlue"></SolidColorBrush>
        <SolidColorBrush x:Key="centerColor" Color="Black"></SolidColorBrush>
        <SolidColorBrush x:Key="fontColor" Color="Black"></SolidColorBrush>
        <LinearGradientBrush x:Key="firstColor" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FF8B8787" Offset="1"/>
            <GradientStop Color="White"/>
        </LinearGradientBrush>
        <SolidColorBrush x:Key="viewColor" Color="YellowGreen"></SolidColorBrush>
    </UserControl.Resources>
    <Viewbox>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="300"></RowDefinition>
                <RowDefinition Height="50"></RowDefinition>
            </Grid.RowDefinitions>
            <Canvas x:Name="canvas" Height="300" Width="300" UseLayoutRounding="True" SnapsToDevicePixels="True">
                <Ellipse Name="firstEllipse" Height="300" Fill="{StaticResource firstColor}" Width="300" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" Panel.ZIndex="0">
                    <!--<Ellipse.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FF8B8787" Offset="1"/>
                        <GradientStop Color="White"/>
                    </LinearGradientBrush>
                </Ellipse.Fill>-->
                    <!--<Ellipse.CacheMode>
                    <BitmapCache/>
                </Ellipse.CacheMode>-->

                </Ellipse>
                <Ellipse Height="270" Width="270" Canvas.Left="15" Canvas.Top="15" Stretch="Fill" Fill="{StaticResource bottomSpaceColor}" Panel.ZIndex="1">
                    <!--<Ellipse.CacheMode>
                    <BitmapCache/>
                </Ellipse.CacheMode>-->
                </Ellipse>
                <Rectangle Name="icoRect" Width="60" Height="40" Canvas.Left="120" Canvas.Top="66" Panel.ZIndex="5">
                    <Rectangle.Fill>
                        <ImageBrush ImageSource="Images/cpu.png"/>
                    </Rectangle.Fill>
                </Rectangle>
                <TextBlock x:Name="viewText" Text="CPU使用率" Foreground="{StaticResource fontColor}" Canvas.Left="120" Canvas.Top="216" Panel.ZIndex="5" FontWeight="Bold"></TextBlock>
                <Ellipse x:Name="viewEllipse" Fill="{StaticResource viewColor}" Width="20" Height="20" Panel.ZIndex="5" Canvas.Left="140" Canvas.Top="240">
                    <!--<Ellipse.Effect>
                    <BlurEffect Radius="12" RenderingBias="Performance"></BlurEffect>
                </Ellipse.Effect>-->
                </Ellipse>
                <!--低于区域-->
                <Path Stroke="Transparent" Fill="{StaticResource lowColor}" StrokeThickness="0" Panel.ZIndex="2">
                    <!--<Path.CacheMode>
                    <BitmapCache/>
                </Path.CacheMode>-->
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="90,253.923">
                                <LineSegment Point="82.5,266.9134"></LineSegment>
                                <ArcSegment Point="33.08657,82.5" Size="135,135"  RotationAngle="90" SweepDirection="Clockwise"/>
                                <LineSegment Point="46.07695,90"/>
                                <ArcSegment Point="90,253.923" Size="120,120"  RotationAngle="90" SweepDirection="Counterclockwise"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <!--正常区域-->
                <Path Stroke="Transparent" Fill="{StaticResource normalColor}" StrokeThickness="0" Panel.ZIndex="2">
                    <!--<Path.CacheMode>
                    <BitmapCache/>
                </Path.CacheMode>-->

                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="46.07695,90">
                                <LineSegment Point="33.08657,82.5"></LineSegment>
                                <ArcSegment Point="266.9134,217.5" Size="135,135"  RotationAngle="180" SweepDirection="Clockwise"/>
                                <LineSegment Point="253.923,210"/>
                                <ArcSegment Point="46.07695,90" Size="120,120"  RotationAngle="180" SweepDirection="Counterclockwise"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <!--超出区域-->
                <Path Stroke="Transparent" Fill="{StaticResource hightColor}" StrokeThickness="0" Panel.ZIndex="2">
                    <!--<Path.CacheMode>
                    <BitmapCache/>
                </Path.CacheMode>-->
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="253.923,210">
                                <LineSegment Point="266.9134,217.5"></LineSegment>
                                <ArcSegment Point="217.5,266.9134" Size="135,135"  RotationAngle="30" SweepDirection="Clockwise"/>
                                <LineSegment Point="210,253.923"/>
                                <ArcSegment Point="253.923,210" Size="120,120"  RotationAngle="30" SweepDirection="Counterclockwise"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Ellipse Height="240" Width="240" Canvas.Left="30" Canvas.Top="30" Stretch="Fill" Fill="{StaticResource mainColor}" Panel.ZIndex="1">
                    <!--<Ellipse.CacheMode>
                    <BitmapCache/>
                </Ellipse.CacheMode>-->
                </Ellipse>
                <Ellipse Height="10" Width="10" Canvas.Left="145" Canvas.Top="145" Stretch="Fill" Fill="White" Panel.ZIndex="10">
                    <!--<Ellipse.CacheMode>
                    <BitmapCache/>
                </Ellipse.CacheMode>-->
                </Ellipse>
                <Ellipse Height="30" Width="30" Canvas.Left="135" Canvas.Top="135" Stretch="Fill" Fill="{StaticResource centerColor}" Panel.ZIndex="9">
                    <!--<Ellipse.CacheMode>
                    <BitmapCache/>
                </Ellipse.CacheMode>-->
                </Ellipse>
                <!--指针-->
                <Path Name="pointerPath" Fill="{StaticResource pointerColor}" Stroke="Transparent" StrokeThickness="0" Panel.ZIndex="8" RenderTransformOrigin="0.939,0.6">
                    <Path.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform Angle="0"/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Path.RenderTransform>
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="160,167.3205">
                                <ArcSegment Point="130,150" Size="40,40" IsLargeArc="False"  RotationAngle="60" SweepDirection="Clockwise"/>
                                <LineSegment Point="92.5,249.5929"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <!--主刻度-->
                <Path Stroke="Transparent" Fill="{StaticResource pathMain}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="89.5,254.7891">
                                <LineSegment Point="83,266.0474"/>
                                <LineSegment Point="80.9849,264.8604"/>
                                <LineSegment Point="87.68039,253.7173"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <TextBlock Canvas.Left="88" Canvas.Top="237" Foreground="{StaticResource fontColor}" Text="0" Panel.ZIndex="6"></TextBlock>
                <TextBlock Canvas.Left="49" Canvas.Top="199" Foreground="{StaticResource fontColor}" Text="10" Panel.ZIndex="6"></TextBlock>
                <TextBlock Canvas.Left="34" Canvas.Top="141" Foreground="{StaticResource fontColor}" Text="20" Panel.ZIndex="6"></TextBlock>
                <TextBlock Canvas.Left="50" Canvas.Top="83" Foreground="{StaticResource fontColor}" Text="30" Panel.ZIndex="6"></TextBlock>
                <TextBlock Canvas.Left="87" Canvas.Top="45" Foreground="{StaticResource fontColor}" Text="40" Panel.ZIndex="6"></TextBlock>
                <TextBlock Canvas.Left="144" Canvas.Top="30" Foreground="{StaticResource fontColor}" Text="50" Panel.ZIndex="6"></TextBlock>
                <TextBlock Canvas.Left="199" Canvas.Top="45" Foreground="{StaticResource fontColor}" Text="60" Panel.ZIndex="6"></TextBlock>
                <TextBlock Canvas.Left="237" Canvas.Top="83" Foreground="{StaticResource fontColor}" Text="70" Panel.ZIndex="6"></TextBlock>
                <TextBlock Canvas.Left="254" Canvas.Top="143" Foreground="{StaticResource fontColor}" Text="80" Panel.ZIndex="6"></TextBlock><
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值