We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SfLinearGauge binding in a ListView

I am trying to include a LinearGauge inside a ListView DataTemplate.  I cannot figure out how to bind the LinearRange StartValue and EndValue.  If I specify a BindingContext per LinearRange, I can get the values set to an initial value in the ViewModel.  But any subsequent changes aren't displayed.

Here is the Xaml within a ViewCell:

<syncfusion:SfLinearGauge BackgroundColor="White" Orientation="OrientationHorizontal" HeightRequest="20" WidthRequest="200" >
                                            <syncfusion:SfLinearGauge.BindingContext>
                                                 <viewModels:ServerViewModel />
                                            </syncfusion:SfLinearGauge.BindingContext>
                                            <syncfusion:SfLinearGauge.Scales>
                                                <syncfusion:LinearScale MinimumValue="0" MaximumValue="100" Interval="20" ScaleBarLength="100"  
                                                    ScaleBarColor="White" LabelColor="White" MinorTicksPerInterval="1" ScaleBarSize="13"
                                                    ScalePosition="Forward" ShowRim="false" ShowLabels="false" >
                                                    <syncfusion:LinearScale.Ranges>
                                                        <syncfusion:LinearRange StartValue="0" EndValue="{Binding Text}" Color="#00853f" StartWidth="10"
                                                                                EndWidth="10" Offset="-0.17" >
                                                                                <syncfusion:LinearRange.BindingContext>
                                                                                     <viewModels:ServerViewModel x:Name="startViewModel" />
                                                                                </syncfusion:LinearRange.BindingContext>
                                                                                </syncfusion:LinearRange>
                                                        <syncfusion:LinearRange StartValue="{Binding TestValue}" EndValue="100" Color="#9fa0a1" StartWidth="10"
                                                                                EndWidth="10" Offset="-0.17">
                                                                                <syncfusion:LinearRange.BindingContext>
                                                                                     <viewModels:ServerViewModel x:Name="endViewModel" />
                                                                                </syncfusion:LinearRange.BindingContext>
                                                                                </syncfusion:LinearRange>
                                                    </syncfusion:LinearScale.Ranges>
                                                </syncfusion:LinearScale>
                                            </syncfusion:SfLinearGauge.Scales>
                                        </syncfusion:SfLinearGauge>
  

Here is the ViewModel property:
private double _value = 10;
        public double TestValue
        {
            set
            {
                if (_value != value)
                {
                    _value = value;
                    OnPropertyChanged();
                }
            }
            get
            {
                return _value;
            }
        }
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;  
        private void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName]string Membername = null)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                System.ComponentModel.PropertyChangedEventArgs propertyChangedEvent 
                = new System.ComponentModel.PropertyChangedEventArgs(Membername);
                handler(this, propertyChangedEvent);
            }
        }
 

How do you correctly bind the StartValue and EndValue?

Thanks! 

3 Replies

PA Paul Anderson S Syncfusion Team April 17, 2015 01:03 PM UTC

Hi Derrick,

Thank you for using syncfusion products.

We have tried to reproduce the reported problem based on the provided code snippet and we are able to reproduce the issue in LinearRange updating dynamically. We would like to ensure whether you wanted to change LinearRange or while changing Symbol/BarPointers,if you could update us the information,it will be conveninent for us to provide you a better solution.


Please let us know if you have any other queries.

Regards,
Paul Anderson


DW Derrick Willer April 17, 2015 03:21 PM UTC

How do you bind a LinearRange StartValue and EndValues then? I am able to bind them to a ViewModel, but only the initial VM property value gets set.  Any subsequent changes to the VM property are not reflected.  Basically, how do you include a LinearGraph that is bindable within a ListView data template.  I guess I could create my own data repeater in code behind by running a foreach loop over the ItemSource collection and then add to a StackLayout.  But I would really like to be able to use MVVM / XAML binding for this.

How do you set the BindingContext for the LinearRange within a Data Template?

Thanks!


PA Paul Anderson S Syncfusion Team April 20, 2015 01:31 PM UTC

Hi Derrick,

We were able to reproduce the issue and have logged defect report regarding this. A support incident to track the status of this defect has been created under your account. Please log on to our support website to check for further updates

https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents

Please let me know if you have any questions.

Regards,
Paul Anderson

Loader.
Live Chat Icon For mobile
Up arrow icon