Back to Devexpress

Scale.CustomElements Property

wpf-devexpress-dot-xpf-dot-gauges-dot-scale-47e4dae7.md

latest5.7 KB
Original Source

Scale.CustomElements Property

Provides access to a collection of custom elements contained in the current Circular Scale or Linear Scale.

Namespace : DevExpress.Xpf.Gauges

Assembly : DevExpress.Xpf.Gauges.v25.2.dll

NuGet Package : DevExpress.Wpf.Gauges

Declaration

csharp
public ScaleCustomElementCollection CustomElements { get; }
vb
Public ReadOnly Property CustomElements As ScaleCustomElementCollection

Property Value

TypeDescription
ScaleCustomElementCollection

A ScaleCustomElementCollection object that contains scale custom elements.

|

Remarks

Use the CustomElements property to add or remove custom elements to the current scale, as well as to customize different settings of individual custom elements. A single custom element is an instance of the ScaleCustomElement class and can be accessed via the GaugeDependencyObjectCollectionBase<T>.Item property of a ScaleCustomElementCollection object.

Example

This example illustrates how to add two buttons as custom elements to the linear scale and use them to increase or decrease the current scale value.

For this, create two ScaleCustomElement objects and add a button control to each custom element.

Finally, to provide the capability for end-users to change the scale’s value, handle the button1_Click and button2_Click events and write code that will increment and decrement the scale value.

View Example

xaml
<Window x:Class="LinearGauge_CustomElement.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxga="http://schemas.devexpress.com/winfx/2008/xaml/gauges"
        Title="MainWindow" Height="450" Width="325">
    <Grid>
        <dxga:LinearGaugeControl Name="linearGaugeControl1" Width="170" >
            <dxga:LinearGaugeControl.Scales>
                <dxga:LinearScale >
                    <dxga:LinearScale.CustomElements>
                        <dxga:ScaleCustomElement VerticalAlignment="Top" HorizontalAlignment="Right">
                            <Button Name="button1" Content="Up" Width="40" Click="button1_Click" />
                        </dxga:ScaleCustomElement>
                        <dxga:ScaleCustomElement VerticalAlignment="Bottom" HorizontalAlignment="Right">
                            <Button Name="button2" Content="Down" Width="40" Click="button2_Click" />
                        </dxga:ScaleCustomElement>
                    </dxga:LinearScale.CustomElements>
                    <dxga:LinearScale.LevelBars >
                        <dxga:LinearScaleLevelBar x:Name="bar" Value="50" />
                    </dxga:LinearScale.LevelBars >
                    <dxga:LinearScale.Layers>
                        <dxga:LinearScaleLayer />
                    </dxga:LinearScale.Layers>
                </dxga:LinearScale>
            </dxga:LinearGaugeControl.Scales>
            <dxga:LinearGaugeControl.Model>
                <dxga:LinearCleanWhiteModel />
            </dxga:LinearGaugeControl.Model>
        </dxga:LinearGaugeControl>
    </Grid>
</Window>
csharp
using System.Windows;

namespace LinearGauge_CustomElement {

    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e) {
            if (bar.Value < 100)
                bar.Value += 10;
        }

        private void button2_Click(object sender, RoutedEventArgs e) {
            if (bar.Value > 0)
                bar.Value -= 10;
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports System.Windows

Namespace LinearGauge_CustomElement

    Partial Public Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
            If bar.Value < 100 Then
                bar.Value += 10
            End If
        End Sub

        Private Sub button2_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
            If bar.Value > 0 Then
                bar.Value -= 10
            End If
        End Sub
    End Class
End Namespace

See Also

Scale Class

Scale Members

DevExpress.Xpf.Gauges Namespace