…
<StackLayout VerticalOptions="Center">
<border:SfBorder BorderColor="Black" BorderWidth="2" >
<gauge:SfLinearGauge HeightRequest="20">
<gauge:SfLinearGauge.Scales>
<gauge:LinearScale MinimumValue="0"
MaximumValue="100"
ShowLabels="False"
ShowTicks="False"
ScaleBarColor="LightGray"
ScaleOffset="0"
ScaleBarSize="20">
<gauge:LinearScale.Pointers>
<gauge:BarPointer Value="{Binding PointerValue}"
Color="{Binding PointerValue, Converter={StaticResource ValueToColorConverter}}"
Thickness="20"
/>
</gauge:LinearScale.Pointers>
</gauge:LinearScale>
</gauge:SfLinearGauge.Scales>
</gauge:SfLinearGauge>
</border:SfBorder>
… |
<ContentPage.Resources>
<ResourceDictionary>
<local:ValueToColorConverter x:Key="ValueToColorConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
…
<gauge:LinearScale.Pointers>
<gauge:BarPointer Value="{Binding PointerValue}"
Color="{Binding PointerValue, Converter={StaticResource ValueToColorConverter}}"
/>
</gauge:LinearScale.Pointers>
… |
…
public class ValueToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((double)value < 30)
{
return Color.Red;
}
else
{
return Color.Green;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
… |