Controlling linearGauge after creating in code.

I am building a series of SfLinearGauge controls in code. However, I am somewhat new to C# and newer to WPF, and don't understand yet how I can set the  linearPointer.Value parameter after the control has been created. The examples on binding mainly refer to XAML and/or controls such as charts, and I have not been able to work out how to apply this understanding to simpler controls. 

Is there an example/FAQ/tutorial on how to drive this parameter? 

Many thanks. 



4 Replies

SS Sridevi Sivakumar Syncfusion Team July 9, 2021 01:51 PM UTC

Hi Ben,

Greetings from Syncfusion.

We have analyzed your requirement, and we can set the pointer value as per below


Solution 1:
Bound the pointers value property with ViewModel and change these properties dynamically.

[Mainpage.Xaml]:
 
 <gauge:LinearScale.Pointers> 
                        <gauge:LinearPointer PointerType="SymbolPointer" 
                                             Value="{Binding SymbolPointer}" 
                                             SymbolPointerHeight="10" 
                                             SymbolPointerWidth="10" 
                                             SymbolPointerPosition="Below" 
                                             SymbolPointerStroke="red" /> 
                        <gauge:LinearPointer PointerType="BarPointer" 
                                             Value="{Binding BarPointer}" 
                                             BarPointerStroke="red" 
                                             BarPointerStrokeThickness="10" /> 
                    </gauge:LinearScale.Pointers> 

[Mainpage.cs]:
 
        private void Button_Click(object sender, RoutedEventArgs e) 
        { 
            var vm = this.DataContext as ViewModel; 
            vm.BarPointer = 80; 
            vm.SymbolPointer = 50; 
        } 

Solution 2:
We can change the poinetr value by accessing the added pointer in code behind.
[Mainpage.Xaml]:
 
                    <gauge:LinearScale.Pointers> 
                        <gauge:LinearPointer PointerType="SymbolPointer" x:Name="symbolPointer" 
                                             SymbolPointerHeight="10" 
                                             SymbolPointerWidth="10" 
                                             SymbolPointerPosition="Below" 
                                             SymbolPointerStroke="red" /> 
                        <gauge:LinearPointer PointerType="BarPointer" x:Name="barPointer" 
                                             BarPointerStroke="red" 
                                             BarPointerStrokeThickness="10" /> 
                    </gauge:LinearScale.Pointers> 

[Mainpage.cs]:
 
        private void Button_Click(object sender, RoutedEventArgs e) 
        { 
            symbolPointer.Value = 80; 
            barPointer.Value = 50; 
        } 

And we can add the pointer dynamically by using the below code snippet in button click.
[Mainpage.cs]:
 
        private void Button2_Click(object sender, RoutedEventArgs e) 
        { 
            LinearPointer linearPointer = new LinearPointer(); 
  
            linearPointer.PointerType = LinearPointerType.SymbolPointer; 
  
            linearPointer.Value = 60; 
  
            linearPointer.SymbolPointerHeight = 15; 
  
            linearPointer.SymbolPointerWidth = 15; 
  
            linearPointer.SymbolPointerPosition = LinearSymbolPointersPosition.Above; 
  
            linearPointer.SymbolPointerStroke = new SolidColorBrush(Color.FromRgb(91, 134, 229)); 
  
            linearScale.Pointers.Add(linearPointer); 
        } 

Please have a sample from the below link
https://www.syncfusion.com/downloads/support/directtrac/general/ze/Gauge_GettingStarted-1011758089

For more information about liner gauge pointers
https://help.syncfusion.com/wpf/linear-gauge/pointers

Let us know if you need any further assistance.

Regards
Sridevi S 
 



OS Ondrej Svoboda July 1, 2024 02:28 PM UTC

Hi,

is there a way how to implement the same using MVVM pattern?

My problem is that if I have bound Pointers collection I can't add new pointers e.g. on button click. It works only in constructor.



VO Vishal Omprasad Syncfusion Team July 8, 2024 11:13 AM UTC

Hi Ondrej,

We have found and fixed the reported scenario “cannot added new pointers dynamically to the bounded Pointers collection” in the WPF SfLinearGauge control from our end.  Currently, the issue fix is in the testing phase. Once the automation is ensured, we will include this issue fix in our upcoming weekly NuGet release update, which is expected to roll out on July 16, 2024. We will update you once the release has been rolled out. We appreciate your patience until then.

Regards,
Vishal O.



VO Vishal Omprasad Syncfusion Team July 16, 2024 11:36 AM UTC

Hi Ondrej,

We have fixed the reported scenario “cannot added new pointers dynamically to the bounded Pointers collection” in the WPF SfLinearGauge control and included the fix in our latest weekly NuGet release update version 26.1.42 which is available for download in nuget.org.

Root-cause: Property changed support for Pointers property is not provided.

We thank you for your support and appreciate your patience in waiting for this update. Please feel free to reach out to us if you would require any further assistance.

Regards,

Vishal O.


Loader.
Up arrow icon