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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Geting expression with result after pressing "=" button

Thread ID:

Created:

Updated:

Platform:

Replies:

147683 Sep 19,2019 03:06 PM UTC Oct 29,2019 09:12 AM UTC UWP 5
loading
Tags: SfCalculator
Michael
Asked On September 19, 2019 03:06 PM UTC

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.

Kanniyappan Panneer Selvam [Syncfusion]
Replied On 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 


Kanniyappan Panneer Selvam [Syncfusion]
Replied On 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 


Kanniyappan Panneer Selvam [Syncfusion]
Replied On 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 + "\n" + "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 


Michael
Replied On October 28, 2019 12:14 PM UTC

Hi,

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

Kanniyappan Panneer Selvam [Syncfusion]
Replied On 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 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon