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>
                <TextBlock Canvas.Left="237" Canvas.Top="199" Foreground="{StaticResource fontColor}" Text="90" Panel.ZIndex="6"></TextBlock>
                <TextBlock Canvas.Left="194" Canvas.Top="237" Foreground="{StaticResource fontColor}" Text="100" Panel.ZIndex="6"></TextBlock>
                <Path Stroke="Transparent" Fill="{StaticResource pathMain}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="45.21093,210.5">
                                <LineSegment Point="33.9526,217"/>
                                <LineSegment Point="32.80096,214.9645"/>
                                <LineSegment Point="44.17101,208.662"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Stroke="Transparent" Fill="{StaticResource pathMain}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="29,150">
                                <LineSegment Point="16,150"/>
                                <LineSegment Point="16.02042,147.6614"/>
                                <LineSegment Point="29.01843,147.8883"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Stroke="Transparent" Fill="{StaticResource pathMain}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="45.21093,89.5">
                                <LineSegment Point="33.9526,83"/>
                                <LineSegment Point="35.13958,80.9849"/>
                                <LineSegment Point="46.28275,87.68039"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Stroke="Transparent" Fill="{StaticResource pathMain}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="89.5,45.21093">
                                <LineSegment Point="83,33.9526"/>
                                <LineSegment Point="85.03551,32.80096"/>
                                <LineSegment Point="91.33804,44.17101"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Stroke="Transparent" Fill="{StaticResource pathMain}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="150,29">
                                <LineSegment Point="150,16"/>
                                <LineSegment Point="152.3386,16.02042"/>
                                <LineSegment Point="152.1117,29.01843"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Stroke="Transparent" Fill="{StaticResource pathMain}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="210.5,45.21093">
                                <LineSegment Point="217,33.9526"/>
                                <LineSegment Point="219.0151,35.13958"/>
                                <LineSegment Point="212.3196,46.28275"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Stroke="Transparent" Fill="{StaticResource pathMain}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="254.7891,89.5">
                                <LineSegment Point="266.0474,83"/>
                                <LineSegment Point="267.199,85.03551"/>
                                <LineSegment Point="255.829,91.33804"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Stroke="Transparent" Fill="{StaticResource pathMain}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="271,150">
                                <LineSegment Point="284,150"/>
                                <LineSegment Point="283.9796,152.3386"/>
                                <LineSegment Point="270.9816,152.1117"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Stroke="Transparent" Fill="{StaticResource pathMain}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="254.7891,210.5">
                                <LineSegment Point="266.0474,217"/>
                                <LineSegment Point="264.8604,219.0151"/>
                                <LineSegment Point="253.7173,212.3196"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Stroke="Transparent" Fill="{StaticResource pathMain}" StrokeThickness="0" Panel.ZIndex="5" RenderTransformOrigin="0.5,0.5">
                    <Path.RenderTransform>
                        <TransformGroup>
                            <RotateTransform Angle="-0.6"/>
                        </TransformGroup>
                    </Path.RenderTransform>
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="211,254.7891">
                                <LineSegment Point="217.4,266.0474"/>
                                <LineSegment Point="215.6645,267.199"/>
                                <LineSegment Point="209.262,255.829"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <!--副刻度-->
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="74.4696,253.9587">
                                <LineSegment Point="71.23678,258.4083"/>
                                <LineSegment Point="69.35679,257.0172"/>
                                <LineSegment Point="72.66677,252.6247"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="64.01672,245.4941">
                                <LineSegment Point="60.3365,249.5814"/>
                                <LineSegment Point="58.61222,248.0014"/>
                                <LineSegment Point="62.36321,243.9789"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="54.50589,235.9833">
                                <LineSegment Point="50.41859,239.6635"/>
                                <LineSegment Point="48.86892,237.9119"/>
                                <LineSegment Point="53.01982,234.3036"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="46.04131,225.5304">
                                <LineSegment Point="41.59172,228.7632"/>
                                <LineSegment Point="40.23363,226.8593"/>
                                <LineSegment Point="44.73896,223.7046"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="32.60941,202.2657">
                                <LineSegment Point="27.58491,204.5027"/>
                                <LineSegment Point="26.65235,202.358"/>
                                <LineSegment Point="31.71513,200.209"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="27.78924,189.7087">
                                <LineSegment Point="22.55843,191.4083"/>
                                <LineSegment Point="21.85516,189.1778"/>
                                <LineSegment Point="27.11484,187.5698"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="24.30804,176.7166">
                                <LineSegment Point="18.92822,177.8602"/>
                                <LineSegment Point="18.46196,175.5684"/>
                                <LineSegment Point="23.86091,174.519"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="22.20393,163.4319">
                                <LineSegment Point="16.73407,164.0068"/>
                                <LineSegment Point="16.5099,161.6789"/>
                                <LineSegment Point="21.98898,161.1995"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="22.20393,136.5681">
                                <LineSegment Point="16.73407,135.9932"/>
                                <LineSegment Point="16.99881,133.6695"/>
                                <LineSegment Point="22.45782,134.3398"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="24.30804,123.2833">
                                <LineSegment Point="18.92822,122.1398"/>
                                <LineSegment Point="19.43442,119.8566"/>
                                <LineSegment Point="24.79345,121.0938"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="27.78924,110.2913">
                                <LineSegment Point="22.55843,108.5917"/>
                                <LineSegment Point="23.30051,106.3739"/>
                                <LineSegment Point="28.50086,108.1645"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="32.60941,97.73434">
                                <LineSegment Point="27.58491,95.49729"/>
                                <LineSegment Point="28.55476,93.36916"/>
                                <LineSegment Point="33.53945,95.69356"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="46.04131,74.4696">
                                <LineSegment Point="41.59172,71.23678"/>
                                <LineSegment Point="42.98284,69.35679"/>
                                <LineSegment Point="47.37534,72.66677"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="54.50589,64.01672">
                                <LineSegment Point="50.41859,60.3365"/>
                                <LineSegment Point="51.9986,58.61222"/>
                                <LineSegment Point="56.02105,62.36321"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="64.01672,54.50589">
                                <LineSegment Point="60.3365,50.41859"/>
                                <LineSegment Point="62.08809,48.86892"/>
                                <LineSegment Point="65.69641,53.01982"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="74.4696,46.04131">
                                <LineSegment Point="71.23678,41.59172"/>
                                <LineSegment Point="73.14075,40.23363"/>
                                <LineSegment Point="76.29543,44.73896"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="97.73434,32.60941">
                                <LineSegment Point="95.49729,27.58491"/>
                                <LineSegment Point="97.64203,26.65235"/>
                                <LineSegment Point="99.79105,31.71513"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="110.2913,27.78924">
                                <LineSegment Point="108.5917,22.55843"/>
                                <LineSegment Point="110.8222,21.85516"/>
                                <LineSegment Point="112.4302,27.11484"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="123.2833,24.30804">
                                <LineSegment Point="122.1398,18.92822"/>
                                <LineSegment Point="124.4316,18.46196"/>
                                <LineSegment Point="125.481,23.86091"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="136.5681,22.20393">
                                <LineSegment Point="135.9932,16.73407"/>
                                <LineSegment Point="138.3211,16.5099"/>
                                <LineSegment Point="138.8005,21.98898"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="163.4319,22.20393">
                                <LineSegment Point="164.0068,16.73407"/>
                                <LineSegment Point="166.3305,16.99881"/>
                                <LineSegment Point="165.6602,22.45782"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="176.7166,24.30804">
                                <LineSegment Point="177.8602,18.92822"/>
                                <LineSegment Point="180.1434,19.43442"/>
                                <LineSegment Point="178.9062,24.79345"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="189.7087,27.78924">
                                <LineSegment Point="191.4083,22.55843"/>
                                <LineSegment Point="193.6261,23.30051"/>
                                <LineSegment Point="191.8355,28.50086"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="202.2657,32.60941">
                                <LineSegment Point="204.5027,27.58491"/>
                                <LineSegment Point="206.6308,28.55476"/>
                                <LineSegment Point="204.3064,33.53945"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="225.5304,46.04131">
                                <LineSegment Point="228.7632,41.59172"/>
                                <LineSegment Point="230.6432,42.98284"/>
                                <LineSegment Point="227.3332,47.37534"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="235.9833,54.50589">
                                <LineSegment Point="239.6635,50.41859"/>
                                <LineSegment Point="241.3878,51.9986"/>
                                <LineSegment Point="237.6368,56.02105"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="245.4941,64.01672">
                                <LineSegment Point="249.5814,60.3365"/>
                                <LineSegment Point="251.1311,62.08809"/>
                                <LineSegment Point="246.9802,65.69641"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="253.9587,74.4696">
                                <LineSegment Point="258.4083,71.23678"/>
                                <LineSegment Point="259.7664,73.14075"/>
                                <LineSegment Point="255.261,76.29543"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="267.3906,97.73434">
                                <LineSegment Point="272.4151,95.49729"/>
                                <LineSegment Point="273.3477,97.64203"/>
                                <LineSegment Point="268.2849,99.79105"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="272.2108,110.2913">
                                <LineSegment Point="277.4416,108.5917"/>
                                <LineSegment Point="278.1448,110.8222"/>
                                <LineSegment Point="272.8852,112.4302"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="275.692,123.2833">
                                <LineSegment Point="281.0718,122.1398"/>
                                <LineSegment Point="281.538,124.4316"/>
                                <LineSegment Point="276.1391,125.481"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="277.7961,136.5681">
                                <LineSegment Point="283.2659,135.9932"/>
                                <LineSegment Point="283.4901,138.3211"/>
                                <LineSegment Point="278.011,138.8005"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="277.7961,163.4319">
                                <LineSegment Point="283.2659,164.0068"/>
                                <LineSegment Point="283.0012,166.3305"/>
                                <LineSegment Point="277.5422,165.6602"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="275.692,176.7166">
                                <LineSegment Point="281.0718,177.8602"/>
                                <LineSegment Point="280.5656,180.1434"/>
                                <LineSegment Point="275.2065,178.9062"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="272.2108,189.7087">
                                <LineSegment Point="277.4416,191.4083"/>
                                <LineSegment Point="276.6995,193.6261"/>
                                <LineSegment Point="271.4991,191.8355"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="267.3906,202.2657">
                                <LineSegment Point="272.4151,204.5027"/>
                                <LineSegment Point="271.4453,206.6308"/>
                                <LineSegment Point="266.4605,204.3064"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="253.9587,225.5304">
                                <LineSegment Point="258.4083,228.7632"/>
                                <LineSegment Point="257.0172,230.6432"/>
                                <LineSegment Point="252.6247,227.3332"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="245.4941,235.9833">
                                <LineSegment Point="249.5814,239.6635"/>
                                <LineSegment Point="248.0014,241.3878"/>
                                <LineSegment Point="243.9789,237.6368"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="235.9833,245.4941">
                                <LineSegment Point="239.6635,249.5814"/>
                                <LineSegment Point="237.9119,251.1311"/>
                                <LineSegment Point="234.3036,246.9802"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Path Tag="pathsub" Stroke="Transparent" Fill="{StaticResource pathSub}" StrokeThickness="0" Panel.ZIndex="5">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigure StartPoint="225.5304,253.9587">
                                <LineSegment Point="228.7632,258.4083"/>
                                <LineSegment Point="226.8593,259.7664"/>
                                <LineSegment Point="223.7046,255.261"/>
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>
            </Canvas>
            <Rectangle Grid.Row="1" Name="rectangle" RenderTransformOrigin="0.5,0.5" Margin="0,0,0,0">
                <Rectangle.Fill>
                    <VisualBrush Visual="{Binding ElementName=canvas}"></VisualBrush>
                </Rectangle.Fill>
                <Rectangle.OpacityMask>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,0.5">
                        <GradientStop Offset="0.01" Color="Transparent"></GradientStop>
                        <GradientStop Offset="0.01" Color="#44000000"></GradientStop>
                    </LinearGradientBrush>
                </Rectangle.OpacityMask>
                <Rectangle.RenderTransform>
                    <ScaleTransform ScaleY="-1"></ScaleTransform>
                </Rectangle.RenderTransform>
            </Rectangle>
        </Grid>

    </Viewbox>
</UserControl>

后台代码:

public class ColorChangedEventArgs : EventArgs
    {
        public string name { get; set; }
        public Color color { get; set; }
        public ColorChangedEventArgs(string name, Color color)
        {
            this.name = name;
            this.color = color;
        }
    }
    public class LinearGradientBrushChangedEventArgs : EventArgs
    {
        public string name { get; set; }
        public LinearGradientBrush brush { get; set; }
        public LinearGradientBrushChangedEventArgs(string name, LinearGradientBrush brush)
        {
            this.name = name;
            this.brush = brush;
        }
    }
    public class AngleChangedEventArgs : EventArgs
    {

        public float angle { get; set; }
        public float oldAngle { get; set; }
        public AngleChangedEventArgs(float angle, float old)
        {
            this.angle = angle;
            this.oldAngle = old;
        }
    }
    public class StringChangedEventArgs : EventArgs
    {
        public string name { get; set; }
        public string text { get; set; }
        public StringChangedEventArgs(string name, string text)
        {
            this.name = name;
            this.text = text;
        }
    }
    /// <summary>
    /// InstrumentControl.xaml 的交互逻辑
    /// </summary>
    public partial class InstrumentControl : UserControl
    {
        public static EventHandler<ColorChangedEventArgs> WhenPropertyChanged;
        public static EventHandler<AngleChangedEventArgs> WhenAnglePropertyChanged;
        public static EventHandler<StringChangedEventArgs> WhenStringPropertyChanged;
        public static EventHandler<LinearGradientBrushChangedEventArgs> WhenBrushChanged;       
        public string ImagePath
        {
            get { return GetValue(ImagePathProperty).ToString(); }
            set { SetValue(ImagePathProperty, value); }
        }
        public string ShowText
        {
            get { return GetValue(ShowTextProperty).ToString(); }
            set { SetValue(ShowTextProperty, value); }
        }
        /// <summary>
        /// 指针颜色
        /// </summary>
        public Color PointerColor
        {
            get { return (Color)GetValue(PointerColorProperty); }
            set { SetValue(PointerColorProperty, value); }
        }
        /// <summary>
        /// 非指示区域处颜色
        /// </summary>
        public Color BottomSpaceColor
        {
            get { return (Color)GetValue(BottomSpaceColorProperty); }
            set { SetValue(BottomSpaceColorProperty, value); }
        }
        /// <summary>
        /// 处于低值时的颜色
        /// </summary>
        public Color LowColor
        {
            get { return (Color)GetValue(LowColorProperty); }
            set { SetValue(LowColorProperty, value); }
        }
        /// <summary>
        /// 正常值颜色
        /// </summary>
        public Color NormalColor
        {
            get { return (Color)GetValue(NormalColorProperty); }
            set { SetValue(NormalColorProperty, value); }
        }
        /// <summary>
        /// 高于正常值颜色
        /// </summary>
        public Color HightColor
        {
            get { return (Color)GetValue(HightColorProperty); }
            set { SetValue(HightColorProperty, value); }
        }
        /// <summary>
        /// 表盘主颜色
        /// </summary>
        public Color MainColor
        {
            get { return (Color)GetValue(MainColorProperty); }
            set { SetValue(MainColorProperty, value); }
        }
        /// <summary>
        ///中心颜色
        /// </summary>
        public Color CenterColor
        {
            get { return (Color)GetValue(CenterColorProperty); }
            set { SetValue(CenterColorProperty, value); }
        }
        /// <summary>
        /// 字体颜色
        /// </summary>
        public Color FontColor
        {
            get { return (Color)GetValue(FontColorProperty); }
            set { SetValue(FontColorProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        public float Angle
        {
            get { return (float)GetValue(AngleProperty); }
            set { SetValue(AngleProperty, value); }
        }


        public LinearGradientBrush FirstCircleBrush
        {
            get { return (LinearGradientBrush)GetValue(FirstCircleBrushProperty); }
            set { SetValue(FirstCircleBrushProperty, value); }
        }

        // Using a DependencyProperty as the backing store for FirstCircleBrush.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FirstCircleBrushProperty =
            DependencyProperty.Register("FirstCircleBrush", typeof(LinearGradientBrush), typeof(InstrumentControl), new PropertyMetadata(new LinearGradientBrush(Colors.Gray, Colors.LightGray, 0f), new PropertyChangedCallback(BrushPropertyChangedCallback)), new ValidateValueCallback(IsLinearGradientBrush));


        public static DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(float), typeof(InstrumentControl), new FrameworkPropertyMetadata(120f, new PropertyChangedCallback(CenterXPropertyChangedCallback)), new ValidateValueCallback(IsFloat)); //属性默认值

        public static DependencyProperty ImagePathProperty = DependencyProperty.Register("ImagePath", typeof(string), typeof(InstrumentControl), new FrameworkPropertyMetadata("Images/cpu.png", new PropertyChangedCallback(StringPropertyChangedCallback))); //属性默认值
        public static DependencyProperty ShowTextProperty = DependencyProperty.Register("ShowText", typeof(string), typeof(InstrumentControl), new FrameworkPropertyMetadata("CPU使用率", new PropertyChangedCallback(StringPropertyChangedCallback))); //属性默认值

        public static DependencyProperty FontColorProperty = DependencyProperty.Register("FontColor", typeof(Color), typeof(InstrumentControl), new FrameworkPropertyMetadata(Colors.Black, new PropertyChangedCallback(ColorPropertyChangedCallback)), new ValidateValueCallback(IsColor));

        public static DependencyProperty CenterColorProperty = DependencyProperty.Register("CenterColor", typeof(Color), typeof(InstrumentControl), new FrameworkPropertyMetadata(Colors.Black, new PropertyChangedCallback(ColorPropertyChangedCallback)), new ValidateValueCallback(IsColor));

        public static DependencyProperty MainColorProperty = DependencyProperty.Register("MainColor", typeof(Color), typeof(InstrumentControl), new FrameworkPropertyMetadata(Colors.AliceBlue, new PropertyChangedCallback(ColorPropertyChangedCallback)), new ValidateValueCallback(IsColor)); //属性默认值

        //public static DependencyProperty FirstCircleColorProperty = DependencyProperty.Register("FirstCircleColor", typeof(LinearGradientBrush), typeof(InstrumentControl), new FrameworkPropertyMetadata(new LinearGradientBrush(Colors.Gray, Colors.LightGray, 0f), new PropertyChangedCallback(BrushPropertyChangedCallback)), new ValidateValueCallback(IsLinearGradientBrush)); //属性默认值

        public static DependencyProperty LowColorProperty = DependencyProperty.Register("LowColor", typeof(Color), typeof(InstrumentControl), new FrameworkPropertyMetadata(Colors.YellowGreen, new PropertyChangedCallback(ColorPropertyChangedCallback)), new ValidateValueCallback(IsColor)); //属性默认值

        public static DependencyProperty HightColorProperty = DependencyProperty.Register("HightColor", typeof(Color), typeof(InstrumentControl), new FrameworkPropertyMetadata(Colors.Red, new PropertyChangedCallback(ColorPropertyChangedCallback)), new ValidateValueCallback(IsColor)); //属性默认值

        public static DependencyProperty NormalColorProperty = DependencyProperty.Register("NormalColor", typeof(Color), typeof(InstrumentControl), new FrameworkPropertyMetadata(Colors.Yellow, new PropertyChangedCallback(ColorPropertyChangedCallback)), new ValidateValueCallback(IsColor)); //属性默认值

        public static DependencyProperty PointerColorProperty = DependencyProperty.Register("PointerColor", typeof(Color), typeof(InstrumentControl), new FrameworkPropertyMetadata(Colors.Black, new PropertyChangedCallback(ColorPropertyChangedCallback)), new ValidateValueCallback(IsColor)); //属性默认值

        public static DependencyProperty BottomSpaceColorProperty = DependencyProperty.Register("BottomSpaceColor", typeof(Color), typeof(InstrumentControl), new FrameworkPropertyMetadata(Colors.AliceBlue, new PropertyChangedCallback(ColorPropertyChangedCallback)), new ValidateValueCallback(IsColor)); //属性默认值

        public static DependencyProperty MajorTickColorProperty = DependencyProperty.Register("MajorTickColor", typeof(Color), typeof(InstrumentControl), new FrameworkPropertyMetadata(Colors.Gray, new PropertyChangedCallback(ColorPropertyChangedCallback)), new ValidateValueCallback(IsColor)); //属性默认值

        public static DependencyProperty MinorTickColorProperty = DependencyProperty.Register("MinorTickColor", typeof(Color), typeof(InstrumentControl), new FrameworkPropertyMetadata(Colors.Chocolate, new PropertyChangedCallback(ColorPropertyChangedCallback)), new ValidateValueCallback(IsColor)); //属性默认值

        private static bool IsLinearGradientBrush(object value)
        {
            // LinearGradientBrush brush = value as LinearGradientBrush;
            return value is LinearGradientBrush;
        }
        private static void BrushPropertyChangedCallback(DependencyObject dp, DependencyPropertyChangedEventArgs e)
        {
            if (WhenBrushChanged != null)
            {
                WhenBrushChanged(dp, new LinearGradientBrushChangedEventArgs(e.Property.Name, (LinearGradientBrush)e.NewValue));
            }
        }
        private static bool IsColor(object value)
        {
            // LinearGradientBrush brush = value as LinearGradientBrush;
            return value is Color;
        }
        private static void ColorPropertyChangedCallback(DependencyObject dp, DependencyPropertyChangedEventArgs e)
        {
            if (WhenPropertyChanged != null)
            {
                WhenPropertyChanged(dp, new ColorChangedEventArgs(e.Property.Name, (Color)e.NewValue));
            }
            //fir
            // LinearGradientBrush brush = value as LinearGradientBrush;
            // return value is LinearGradientBrush;
        }
        private static void StringPropertyChangedCallback(DependencyObject dp, DependencyPropertyChangedEventArgs e)
        {
            if (WhenStringPropertyChanged != null)
            {
                WhenStringPropertyChanged(dp, new StringChangedEventArgs(e.Property.Name, e.NewValue.ToString()));
            }
        }
        private static bool IsFloat(object value)
        {
            // LinearGradientBrush brush = value as LinearGradientBrush;
            float a = 0f;
            return float.TryParse(value.ToString(), out a);
        }
        private static void CenterXPropertyChangedCallback(DependencyObject dp, DependencyPropertyChangedEventArgs e)
        {
            if (WhenAnglePropertyChanged != null)
            {
                WhenAnglePropertyChanged(dp, new AngleChangedEventArgs((float)e.NewValue, (float)e.OldValue));
            }
        }
        public InstrumentControl()
        {
            InitializeComponent();
            this.Loaded += InstrumentControl_Loaded;
            RenderOptions.SetBitmapScalingMode(canvas, BitmapScalingMode.LowQuality);
            WhenPropertyChanged += new EventHandler<ColorChangedEventArgs>(ColorChanged);
            WhenAnglePropertyChanged += new EventHandler<AngleChangedEventArgs>(AngleChanged);
            WhenStringPropertyChanged += new EventHandler<StringChangedEventArgs>(StringChanged);
            WhenBrushChanged += new EventHandler<LinearGradientBrushChangedEventArgs>(BrushChanged);

        }
        ~InstrumentControl() { }
        private void StringChanged(object o, StringChangedEventArgs e)
        {          
            if (o is InstrumentControl)
            {
                InstrumentControl instrumentControl = o as InstrumentControl;
                switch (e.name)
                {
                    case "ImagePath":
                        ImageBrush brush = new ImageBrush(new BitmapImage(new Uri(ImagePath, UriKind.RelativeOrAbsolute)));
                        instrumentControl.icoRect.Fill = brush;
                        break;
                    case "ShowText":
                        instrumentControl.viewText.Text = e.text;
                        break;
                }
            }          
        }      
        private void AngleChanged(object o, AngleChangedEventArgs e)
        {
            if (o is InstrumentControl)
            {
                InstrumentControl instrumentControl = o as InstrumentControl;
                SolidColorBrush solidBrush = instrumentControl.FindResource("viewColor") as SolidColorBrush;
                if (e.angle <= 90)//low lowColor
                {
                    SolidColorBrush solidBrush2 = instrumentControl.FindResource("lowColor") as SolidColorBrush;
                    solidBrush.Color = solidBrush2.Color;
                }
                else if (e.angle >= 270) //hight hightColor
                {
                    SolidColorBrush solidBrush2 = instrumentControl.FindResource("hightColor") as SolidColorBrush;
                    solidBrush.Color = solidBrush2.Color;
                }
                else //normal normalColor
                {
                    SolidColorBrush solidBrush2 = instrumentControl.FindResource("normalColor") as SolidColorBrush;
                    solidBrush.Color = solidBrush2.Color;
                }
                //instrumentControl.viewEllipse.Fill = solidBrush;
                Storyboard storyboard = new Storyboard();
                //storyboard.Completed += storyboard_Completed;
                storyboard.AutoReverse = false;
                storyboard.FillBehavior = FillBehavior.HoldEnd;
                DoubleAnimation doubleAnimationX = new DoubleAnimation(e.oldAngle, e.angle, new Duration(TimeSpan.FromMilliseconds(500)));
                Storyboard.SetTarget(doubleAnimationX, instrumentControl.pointerPath);
                Storyboard.SetTargetProperty(doubleAnimationX, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"));
                storyboard.Children.Add(doubleAnimationX);
                storyboard.AutoReverse = false;
                storyboard.AccelerationRatio = 0.3;
                storyboard.DecelerationRatio = 0.2;
                storyboard.Begin();
            }

        }

        void storyboard_Completed(object sender, EventArgs e)
        {
            // storyboard.Completed -= storyboard_Completed;
            //storyboard.Stop();
            if (sender is ClockGroup)
            {
                ClockGroup c = sender as ClockGroup;
                Storyboard storybord = c.Timeline as Storyboard;
                //Storyboard storybord =(StopStoryboard)sender;
                storybord.Stop();
                storybord = null;
            }

            //throw new NotImplementedException();
        }
        void InstrumentControl_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void BrushChanged(object o, LinearGradientBrushChangedEventArgs e)
        {
            if (o is InstrumentControl)
            {
                InstrumentControl instrumentControl = o as InstrumentControl;
                switch (e.name)
                {
                    case "FirstCircleBrush":
                        LinearGradientBrush solidBrush = instrumentControl.FindResource("firstColor") as LinearGradientBrush;
                        solidBrush = e.brush;
                        instrumentControl.firstEllipse.Fill = solidBrush;
                        break;
                }
            }         

        }
        private void ColorChanged(object o, ColorChangedEventArgs e)
        {
            if (o is InstrumentControl)
            {
                InstrumentControl instrumentControl = o as InstrumentControl;
                switch (e.name)
                {
                    case "MajorTickColor":
                        SolidColorBrush solidBrush = instrumentControl.FindResource("pathMain") as SolidColorBrush;
                        solidBrush.Color = e.color;

                        break;
                    //case "FirstCircleColor":
                    //    SolidColorBrush solidBrush = instrumentControl.FindResource("firstColor") as SolidColorBrush;
                    //    solidBrush.Color = e.color;

                    //    break;
                    case "MinorTickColor":
                        SolidColorBrush solidBrush2 = instrumentControl.FindResource("pathSub") as SolidColorBrush;
                        solidBrush2.Color = e.color;
                        break;
                    case "PointerColor":
                        SolidColorBrush solidBrush3 = instrumentControl.FindResource("pointerColor") as SolidColorBrush;
                        solidBrush3.Color = e.color;
                        break;
                    case "BottomSpaceColor":
                        SolidColorBrush bottomSpaceColor = instrumentControl.FindResource("bottomSpaceColor") as SolidColorBrush;
                        bottomSpaceColor.Color = e.color;
                        break;
                    case "LowColor":
                        SolidColorBrush lowColor = instrumentControl.FindResource("lowColor") as SolidColorBrush;
                        lowColor.Color = e.color;
                        break;
                    case "NormalColor":
                        SolidColorBrush normalColor = instrumentControl.FindResource("normalColor") as SolidColorBrush;
                        normalColor.Color = e.color;
                        break;
                    case "HightColor":
                        SolidColorBrush hightColor = instrumentControl.FindResource("hightColor") as SolidColorBrush;
                        hightColor.Color = e.color;
                        break;
                    case "MainColor":
                        SolidColorBrush mainColor = instrumentControl.FindResource("mainColor") as SolidColorBrush;
                        mainColor.Color = e.color;
                        break;
                    case "CenterColor":
                        SolidColorBrush centerColor = instrumentControl.FindResource("centerColor") as SolidColorBrush;
                        centerColor.Color = e.color;
                        break;
                    case "FontColor":
                        SolidColorBrush fontColor = instrumentControl.FindResource("fontColor") as SolidColorBrush;
                        fontColor.Color = e.color;
                        break;
                    //centerColor
                }
            }
        }

        public Color MajorTickColor
        {
            get { return (Color)GetValue(MajorTickColorProperty); }
            set { SetValue(MajorTickColorProperty, value); }
        }
        // private Color minorTickColor = Colors.Gray;

        public Color MinorTickColor
        {
            get { return (Color)GetValue(MinorTickColorProperty); }
            set { SetValue(MinorTickColorProperty, value); }
        }

    }
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值