New to Telerik UI for WinUI? Download free 30-day trial

How to Bind to Business Objects

This article will demonstrate how to bind the RadGauge indicator properties to business objects.

In this example we will use the RadLinearGauge control to display some temperature ranges and update the temperature value through a view model.

  1. First, let us create a ViewModel class. It is important that the ViewModel implements the INotifyPropertyChanged interface and raises the PropertyChanged event for the properties that will be updated runtime. This will be achieved by inheriting the ViewModelBase class from the "Telerik.Core" namespace, which implements that interface.

    Example 1: Creating the ViewModel

        public class ViewModel : ViewModelBase 
            private double temperature; 
            public ViewModel() 
                this.Temperature = 35; 
                this.Min = 20; 
                this.Average = 30; 
                this.Max = 50; 
            public double Temperature 
                    return this.temperature; 
                    if (this.temperature != value) 
                        this.temperature = value; 
            public double Min { get; set; } 
            public double Average { get; set; } 
            public double Max { get; set; } 
  2. Then, let us create the RadLinearGauge control with several indicators.

    Example 2: Setting up the view

        <Grid xmlns:dataVisualization="using:Telerik.UI.Xaml.Controls.DataVisualization"> 
            <dataVisualization:RadLinearGauge MaxValue="100" MinValue="0" Orientation="Vertical" Height="300"> 
                <dataVisualization:SegmentedLinearGaugeIndicator Value="100" > 
                    <dataVisualization:BarIndicatorSegment Stroke="Green" Length="{Binding Min}"/> 
                    <dataVisualization:BarIndicatorSegment Stroke="Orange" Length="{Binding Average}"/> 
                    <dataVisualization:BarIndicatorSegment Stroke="Red" Length="{Binding Max}"/> 
                <dataVisualization:MarkerGaugeIndicator Value="{Binding Temperature}"> 
                        <TextBlock Foreground="Gray" Margin="0,0,50,0"> 
                            <Run Text="{Binding Temperature}"/> 
                            <Run Text="°C"/> 
                <dataVisualization:MarkerGaugeIndicator Value="{Binding Temperature}"> 
                        <Rectangle Fill="Gray" Width="10" Height="10"/> 
  3. Now, if we update the Temperature property, the RadLinearGauge will update its indicators.

    Figure 1: Result from Examples 1 and 2

    How To Bind To View Model Example

See Also

In this article
Not finding the help you need?