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

Geting expression with result after pressing "=" button

Hi,

I'm using solution from https://www.syncfusion.com/forums/146912/styling-sfcalculator to able able to style SfCalculator. It works fine. Now I would like to get expression and result from SfCalculator after pressing "=" button on this calculator.

I want to store this in my ObservableCollection that is in my ViewModel for the View that SfCalculator is placed on. I prefer to use Command with parameter (this parameter should be an expression with the result, for example, 2+2 = 4) but I will take a solution that uses code-behind if there is no other option.

I tried to use Click event and KeyUp event that this button has but it wasn't exactly what I want.

5 Replies

KP Kanniyappan Panneer Selvam Syncfusion Team September 20, 2019 05:35 PM UTC

 
Hi Michael, 
 
Thanks for contacting Syncfusion support. 
 
Currently we are working on your queries at our end and we will provide more details on 23rd, September 2019. 
 
We appreciate your patience until then. 
 
Regards, 
Kanniyappan P 



KP Kanniyappan Panneer Selvam Syncfusion Team September 23, 2019 04:00 PM UTC

Hi Michael, 
 
Sorry for the delay. 
 
Currently we are working on to prepare a sample based on your requirement with high priority and we will update you the details with sample on 25th September, 2019. 
 
We appreciate your patience until then. 
 
Regards, 
Kanniyappan P 



KP Kanniyappan Panneer Selvam Syncfusion Team September 25, 2019 11:30 AM UTC

Hi Michael, 
 
Thanks for your patience. 
 
We have checked your query “Get expression and result value from calculator in MVVM pattern” at our end. We have prepared the sample based on your requirement. In our sample, we have get the expression and result value from calculator using commands. Please find the code snippet, screenshot and sample for the same. 
 
Code Snippet: 
 
XAML 
 
<input:SfCalculator x:Name="calculator"  Width="400" DisplayText="{Binding DisplayText,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Expression="{Binding ExpressionText,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  Style="{StaticResource DefaultSfCalculatorStyle}"  FunctionsPaneStyle="{StaticResource SfCalculatorFunctionsPaneStyle1}"   Height="600" /> 
  
<input:CalculatorButton Key="Number7" Command="{Binding CalculatorExpression}" IsTabStop="False" Foreground="{TemplateBinding Foreground}" 
                                                Content="7" x:Name="Digit7" > 
 
 
<input:CalculatorButton x:Name="PART_Button17" BrushOpacity="0.3" Click="PART_Button17_Click" Command="{Binding ComputeValue}" CommandParameter="{Binding ElementName=calculator, Path=Value}" Content="=" Grid.Column="4" Function="Return" Foreground="{TemplateBinding Foreground}" FontSize="35" IsTabStop="False" Grid.RowSpan="2" Grid.Row="4"/> 
 
Result: 
 
<input:CalculatorButton x:Name="PART_Button17" BrushOpacity="0.3" Click="PART_Button17_Click" Command="{Binding ComputeValue}" CommandParameter="{Binding ElementName=calculator, Path=Value}" Content="=" Grid.Column="4" Function="Return" Foreground="{TemplateBinding Foreground}" FontSize="35" IsTabStop="False" Grid.RowSpan="2" Grid.Row="4"/> 
 
C# 
private void Expression(object obj) 
       
            _expression = ExpressionText + DisplayText; 
       
 
  private void ComputationValue(object obj) 
       
            if (obj != null
           
                var result = obj;             
                ContentDialog dialog = new ContentDialog(); 
                dialog.Content = "Expression is :  " + _expression + "" + "Result is : " + result.ToString(); 
                dialog.IsPrimaryButtonEnabled = true
                dialog.PrimaryButtonText = "Ok"
                dialog.PrimaryButtonClick += Dialog_PrimaryButtonClick; 
                dialog.ShowAsync(); 
           
       
 
  
Screenshot: 
 
 
 
 
Please try the above solution and let us know if it is helpful. 
 
Regards, 
Kanniyappan P 



MI Michael October 28, 2019 12:14 PM UTC

Hi,

This is exactly what I wanted. Thank you so much :) 


KP Kanniyappan Panneer Selvam Syncfusion Team October 29, 2019 09:12 AM UTC

Hi Michael,  
  
Thanks for you update.  
  
We are glad to know that the reported issue has been resolved at your end. Please let us know if you need any further assistance on this. We are happy to help you.  
  
Regards,  
Kanniyappan P 
 


Loader.
Live Chat Icon For mobile
Up arrow icon