Annotation - dynamic alignment

Hi,

I'm trying to get my horizontal alignment in a lineargauge annoation to be dynamic. When my value is 0 or near it, i want it to be "start" so it doesn't drop off the left of the contol. Similar, if it's near 100% of the range, i want it to be "end" so it doesn't drop off. I've tried binding, and a value converter, neither seemed to work. Should this work?


<gauges:LinearGaugeAnnotation HorizontalViewAlignment="{binding myByinding"
                                                              ScaleValue="{Binding scale}"
                                                              VerticalViewAlignment="Start">
                                    <gauges:LinearGaugeAnnotation.View>
                                        <StackLayout>
                                            <Label Style="{StaticResource MicroLabel}" Text="{Binding text, Converter={StaticResource CurrencyConverter}}" />
                                        </StackLayout>
                                    </gauges:LinearGaugeAnnotation.View>
                                </gauges:LinearGaugeAnnotation>

3 Replies 1 reply marked as answer

SS Sridevi Sivakumar Syncfusion Team July 6, 2020 10:08 AM UTC

Hi Mark, 
 
Greetings from syncfusion. 
 
Query: When my value is 0 or near it, i want it to be "start" so it doesn't drop off the left of the control. 
 
We have checked the reported query and we would like to let you know that you can customize the annotation alignment using HorizontalViewAlignment based on the scale value in linear gauge. We have changed its position to end once it reaches 100 and start again when it reaches 0 as per in below 
 
Code snippet: 
       <gauge:LinearGaugeAnnotation ScaleValue ="{Binding ScaleValue, Mode=TwoWay}"          x:Name="annotation" HorizontalViewAlignment="{Binding  ScaleValue,Converter={StaticResource    doubleToalignmentConverter}}"> 
               <gauge:LinearGaugeAnnotation.View> 
                        <Label Text="CPU Utilization" WidthRequest="110" FontAttributes = "Bold" TextColor= "Black" FontSize ="15"/> 
                </gauge:LinearGaugeAnnotation.View> 
         </gauge:LinearGaugeAnnotation> 
 
  
public class DoubleToalignmentConverter : IValueConverter 
    { 
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
        { 
            return (int)value == 0 ? ViewAlignment.Start : (int)value == 100 ? ViewAlignment.End : ViewAlignment.Center; 
        } 
.. 
    } 
 
  

Please check this and let us know. 
 
Regards, 
Sridevi S. 
 


Marked as answer

MA Mark July 6, 2020 10:52 AM UTC

Fantastic, that helped, I'm not sure what i did wrong originally given I had conceptually the same code, but re-doing it from scratch based on your example now works. Thanks!


HM Hemalatha Marikumar Syncfusion Team July 7, 2020 07:21 AM UTC

Hi Mark, 
 
We are glad to hear that given solution resolves your issue.  
 
Please let us know if you need any further assistance, don’t hesitate to contact us.  
 
Regards,
Hemalatha M. 


Loader.
Up arrow icon