This is a migrated thread and some comments may be shown as answers.

GaugeRange Min Max databinding problem with Loaded event

1 Answer 69 Views
Gauges
This is a migrated thread and some comments may be shown as answers.
feng
Top achievements
Rank 1
feng asked on 23 Jun 2015, 08:05 AM

Hi 

I am using latest version, and I found a problem about data binding  Min and Max in GaugeRange.

Xaml like this.

<Window x:Class="TelerikChartTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        Title="MainWindow"
        Height="350"
        Width="525">
    <Window.Resources>

    </Window.Resources>
    <Grid>

        <telerik:RadRadialGauge x:Name="radialGauge"
                                Width="200"
                                Height="200"
                                telerik:StyleManager.Theme="Windows8">
            <telerik:RadialScale Name="scale"
                                 LabelRotationMode="None"
                                 Min="{Binding Path=Min}"
                                 Max="{Binding Path=Max}"
                                 StartWidth="0.1"
                                 EndWidth="0.1"
                                 MajorTicks="4">
                <telerik:RadialScale.Ranges>
                    <telerik:GaugeRange x:Name="range1" 
                                        Min="{Binding ElementName=radialGauge, Path=DataContext.Min1, NotifyOnTargetUpdated=True}"
                                        Max="{Binding ElementName=radialGauge, Path=DataContext.Max1, NotifyOnTargetUpdated=True}"
                                        Background="#FF1E8D00" />

                </telerik:RadialScale.Ranges>
            </telerik:RadialScale>
        </telerik:RadRadialGauge>
       
    </Grid>
</Window>

in cs file like this,

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;

        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = new TestData();
          
        }
        
    }

    public class TestData : ViewModelBase
    {
        private float _min = 0;
        public float Min
        {
            get { return _min; }
            set
            {
                _min = value;
                this.OnPropertyChanged("Min");
            }
        }


        private float _min1 = 0;
        public float Min1
        {
            get { return _min1; }
            set
            {
                _min1 = value;
                this.OnPropertyChanged("Min1");
            }
        }

        private float _max = 1000;
        public float Max
        {
            get { return _max; }
            set
            {
                _max = value;
                this.OnPropertyChanged("Max");
            }
        }

        private float _max1 = 1000;
        public float Max1
        {
            get { return _max1; }
            set
            {
                _max1 = value;
                this.OnPropertyChanged("Max1");
            }
        }

    }
if I set the DataConxtext in  MainWindow_Loaded event, the display of GaugeRange  will be mess. I found if we do not set max and min value before loaded event, the display will be wrong, but in some case, the min and max value maybe get updated after loaded event, how can we handle it?

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 25 Jun 2015, 08:16 AM
Hello,

I modified your sample a little and everything works as expected on my side. No matter if you set the DataContext for the MainWindow on Loaded event or right after the InitializeComponent() constructor the Min And Max bindings will work.
You might find attached my test project.

Regards,
Evgenia
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Gauges
Asked by
feng
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or