Click here to Skip to main content
15,885,985 members
Articles / Web Development / HTML

Circular Gauge Custom Control for Silverlight 3 and WPF

Rate me:
Please Sign up or sign in to vote.
4.97/5 (71 votes)
22 Jul 2009BSD4 min read 419.5K   22.3K   157  
An article on creating a circular gauge custom control for Silverlight 3
<UserControl xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"  x:Class="CircularGaugeDemo.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:gauge="clr-namespace:CircularGauge;assembly=CircularGauge">
    <Grid x:Name="LayoutRoot" >
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF552322" Offset="1"/>
                <GradientStop Color="#FFFFFFFF" Offset="0"/>
            </LinearGradientBrush>
        </Grid.Background>
        <Grid >
            <Grid.RowDefinitions>
                <RowDefinition Height="330" />
                <RowDefinition Height="330"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="330" />
                <ColumnDefinition Width="330"/>
            </Grid.ColumnDefinitions>
       

                    <!--Black Gauge -->
                    <gauge:CircularGaugeControl x:Name="myGauge1" Grid.Column="0" Grid.Row="0" 
                                        Radius="150" 
                                        ScaleRadius="110" 
                                        ScaleStartAngle="120" 
                                        ScaleSweepAngle="300"
                                        PointerLength="85" 
                                        PointerCapRadius="35" 
                                        MinValue="0" 
                                        MaxValue="1000" 
                                        MajorDivisionsCount="10" 
                                        MinorDivisionsCount="5" 
                                        CurrentValue="{Binding Score}"
                                        ImageSource="silverlightlogo.png"
                                        ImageSize="60,50"
                                        RangeIndicatorThickness="8"
                                        RangeIndicatorRadius="120"
                                        RangeIndicatorLightRadius="10"
                                        RangeIndicatorLightOffset="80"
                                        ScaleLabelRadius="90"
                                        ScaleLabelSize="40,20"
                                        ScaleLabelFontSize="10"
                                        ScaleLabelForeground="LightGray"
                                        MajorTickSize="10,3"
                                        MinorTickSize="3,1"
                                        MajorTickColor="LightGray"
                                        MinorTickColor="LightGray"
                                        ImageOffset="-50"
                                        GaugeBackgroundColor="Black"
                                        PointerThickness ="16"
                                        OptimalRangeStartValue="300"
                                        OptimalRangeEndValue="700" 
                                        DialTextOffset="40" 
                                        DialText="Black"
                                        DialTextColor="Black"
                                        >                            

                    </gauge:CircularGaugeControl>

            <!--Blue Gauge -->
            <gauge:CircularGaugeControl x:Name="myGauge2"  Grid.Column="1" Grid.Row="0"
                                        Radius="150" 
                                        ScaleRadius="100" 
                                        ScaleStartAngle="140" 
                                        ScaleSweepAngle="270"
                                        PointerLength="90" 
                                        PointerCapRadius="35" 
                                        MinValue="0" 
                                        MaxValue="1" 
                                        MajorDivisionsCount="10" 
                                        MinorDivisionsCount="5" 
                                        OptimalRangeEndValue="0.8"
                                        OptimalRangeStartValue="0.5"
                                        CurrentValue="{Binding Score}"
                                        ImageSource="silverlightlogo.png"
                                        ImageSize="60,50"
                                        RangeIndicatorThickness="9"
                                        RangeIndicatorRadius="80"
                                        RangeIndicatorLightRadius="10"
                                        RangeIndicatorLightOffset="80"
                                        ScaleLabelRadius="115"
                                        ScaleLabelSize="40,20"
                                        ScaleLabelFontSize="10"
                                        ScaleLabelForeground="White"
                                        MajorTickSize="10,3"
                                        MinorTickSize="3,1"
                                        MajorTickColor="White"
                                        MinorTickColor="LightGray"
                                        ImageOffset="-50"
                                        GaugeBackgroundColor="CornflowerBlue"
                                        PointerThickness ="5"
                                        DialTextOffset="40"
                                        DialText="Aqua Blue"
                                        DialTextColor="DarkBlue"
                                        
                                        />

            
            <!--Red Gauge -->
            <gauge:CircularGaugeControl x:Name="myGauge3" Grid.Column="0" Grid.Row="1"
                                        Radius="150" 
                                        ScaleRadius="90" 
                                        ScaleStartAngle="120" 
                                        ScaleSweepAngle="300"
                                        PointerLength="80" 
                                        PointerCapRadius="45" 
                                        MinValue="-50" 
                                        MaxValue="50" 
                                        MajorDivisionsCount="10" 
                                        MinorDivisionsCount="5" 
                                        OptimalRangeStartValue="-10"
                                        OptimalRangeEndValue="30"
                                        CurrentValue="{Binding Score}"
                                        ImageSource="silverlightlogo.png"
                                        ImageSize="60,50"
                                        RangeIndicatorThickness="0"
                                        RangeIndicatorRadius="0"
                                        RangeIndicatorLightRadius="10"
                                        RangeIndicatorLightOffset="80"
                                        ScaleLabelRadius="110"
                                        ScaleLabelSize="40,20"
                                        ScaleLabelFontSize="10"
                                        ScaleLabelForeground="White"
                                        MajorTickSize="13,3"
                                        MinorTickSize="5,1"
                                        MajorTickColor="White"
                                        MinorTickColor="LightGray"
                                        ImageOffset="-50"
                                        GaugeBackgroundColor="DarkRed"
                                        PointerThickness ="20"
                                        DialTextOffset="40"
                                        DialText="Dark Red"
                                        DialTextColor="DarkRed"
                                        />

            <!--DarkSlateGray gauge-->
            <gauge:CircularGaugeControl x:Name="myGauge4" Grid.Column="1" Grid.Row="1" 
                                        Radius="150" 
                                        ScaleRadius="110" 
                                        ScaleStartAngle="120" 
                                        ResetPointerOnStartUp="True"
                                        ScaleSweepAngle="300"
                                        PointerLength="85" 
                                        PointerCapRadius="35" 
                                        MinValue="0" 
                                        MaxValue="1000" 
                                        MajorDivisionsCount="10" 
                                        MinorDivisionsCount="5" 
                                        CurrentValue="{Binding Score}"
                                        ImageSource="silverlightlogo.png"
                                        ImageSize="60,50"
                                        RangeIndicatorThickness="0"
                                        RangeIndicatorRadius="0"
                                        ScaleLabelRadius="90"
                                        ScaleLabelSize="40,20"
                                        ScaleLabelFontSize="11"
                                        ScaleLabelForeground="Black"
                                        MajorTickSize="10,3"
                                        MinorTickSize="3,1"
                                        MajorTickColor="DarkGray"
                                        MinorTickColor="DarkGray"
                                        ImageOffset="-50"
                                        GaugeBackgroundColor="DarkSlateGray"
                                        PointerThickness ="12"
                                        OptimalRangeStartValue="300"
                                        OptimalRangeEndValue="700" 
                                        DialTextOffset="40"
                                        DialText="Slate Gray"
                                        DialTextColor="DarkSlateGray"
                                        >


            </gauge:CircularGaugeControl>


        </Grid>
    </Grid>
</UserControl>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Web Developer
United States United States
I have worked mainly with ASP.NET but also have exposure to Windows forms, WPF and Silverlight. I also enjoy developing user interfaces using Expression Blend.

Comments and Discussions