Articles in this section
Category / Section

How to apply themes for SfDigitalGauge?

2 mins read

This section tells you how to apply custom themes for WPF SfDigitalGauge. You can define custom styles for controls using Resource Dictionary that contains resources as well as styles for components.

Note:

Implementation and APIs are similar in WPF, Silverlight and WinRT Platforms. You can refer this article for other platforms too.

Steps to apply themes for Digital Gauge:

1. Create a WPF application and add SfDigitalGauge control as follows.

XAML

        <syncfusion:SfDigitalGauge/>

2. To specify the styles for required controls, add a resource dictionary in the application. To add a resource dictionary, right-click on the WPF project and then click “Add” button. Select “Resource Dictionary” by giving a name for the resource dictionary file (for example: MetroTheme.xaml). Add the necessary styles in the created resource dictionary as follows.

XAML

    <!--Metro Style for Digital Gauge -->    
    <Style TargetType="syncfusion:SfDigitalGauge">
        <Setter Property="Width" Value="550"/>
        <Setter Property="Height" Value="80"/>
        <Setter Property="CharacterType" Value="EightCrossEightDotMatrix"/>
        <Setter Property="CharacterStroke" Value="#41B0DF"/>
        <Setter Property="CharacterWidth" Value="50"/>
        <Setter Property="CharacterHeight" Value="50"/>
        <Setter Property="CharactersSpacing" Value="10"/>
        <Setter Property="SegmentThickness" Value="4"/>
    </Style> 

3. This resource dictionary is merged with the resources of application to share the custom styles defined for DigitalGauge.

XAML

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Themes/MetroTheme.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

Else, you can merge the resource dictionary in code-behind as follows.

WPF / Silverlight:

C#

            ResourceDictionary resourceDictionary = new ResourceDictionary();
            resourceDictionary.Source = new Uri("/DigitalGaugeThemesDemo;component/Themes/MetroTheme.xaml", UriKind.RelativeOrAbsolute);
            Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);        

 

WinRT:

C#

            ResourceDictionary resourceDictionary = new ResourceDictionary();
            resourceDictionary.Source = new 
Uri("ms-appx:///Themes/MetroTheme.xaml", UriKind.RelativeOrAbsolute);                                            
            Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);        

4. In result, the digital gauge is displayed with Metro style as follows.

Metro Theme for SfDigitalGauge

Figure 1: Metro Theme for Digital Gauge

You can define and apply any style or theme for digital gauge. To achieve this requirement, a sample containing 7 different themes like Metro, Blend, Almond, Sandune, Office Blue, Office Black and Office Silver is defined and attached in the following sample link for reference.

Sample Link:

DigitalGaugeThemesDemo_WPF.zip

SfDigitalGauge with various themes

Figure 2: Digital Gauge with various themes

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied