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!