GaugeRange Min Max databinding problem with Loaded event

2 posts, 0 answers
  1. feng
    feng avatar
    1 posts
    Member since:
    Jun 2015

    Posted 23 Jun 2015 Link to this post

    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?

  2. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 25 Jun 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top