Visual Studio LightSwitch is a Microsoft tool,
which is used to build business applications. If you want use of the system
calculator in our LightSwitch application then just follow these steps.
Step by step solution
Step 1 : Open Visual Studio
LightSwitch->Go to solution explorer and click the file view.
Step 2 : Right click on
client->Add->Class.
Step 3 : Select class->Write name
(Calculator.cs)->Add.
Code :
using System;
using
System.Net;
using
System.Text;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Ink;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
using
System.Runtime.InteropServices;
using
System.Runtime.InteropServices.Automation;
namespace
LightSwitchApplication
{
public class
Calculator
{
public static
void ShowCalculator()
{
dynamic calc =
AutomationFactory.CreateObject("WScript.Shell");
calc.Run(@"%SystemRoot%\system32\calc.exe");
}
}
}
Step 4 : Now go to solution
explorer then click on logical view.
Step 5 : Right click on screens->Add
screen.
Step 6 : Select new data screen->Ok.
Step 7 : Now add data item->Select
method->Write name (ShowCalculator)->Ok.
Step 8 : Move showcalculator to screen
commandbar.
Step 9 : Right click on showcalculator
method->Edit canexecute code->Write the code.
Code :
using
System;
using
System.Linq;
using System.IO;
using
System.IO.IsolatedStorage;
using
System.Collections.Generic;
using
Microsoft.LightSwitch;
using
Microsoft.LightSwitch.Framework.Client;
using
Microsoft.LightSwitch.Presentation;
using
Microsoft.LightSwitch.Presentation.Extensions;
using
System.Runtime.InteropServices.Automation;
namespace
LightSwitchApplication
{
public partial
class CreateNew
{
partial void
ShowCalculator_CanExecute(ref
bool result)
{
// Write your code here.
result = AutomationFactory.IsAvailable;
}
}
}
Step 10 : Again right click
on showcalculator method->Edit execute code.
Code :
using
System.Linq;
using System.IO;
using
System.IO.IsolatedStorage;
using
System.Collections.Generic;
using
Microsoft.LightSwitch;
using
Microsoft.LightSwitch.Framework.Client;
using
Microsoft.LightSwitch.Presentation;
using
Microsoft.LightSwitch.Presentation.Extensions;
using
System.Runtime.InteropServices.Automation;
namespace
LightSwitchApplication
{
public partial
class CreateNew
{
partial void
ShowCalculator_CanExecute(ref
bool result)
{
// Write your code here.
result = AutomationFactory.IsAvailable;
}
partial void
ShowCalculator_Execute()
{
// Write your code here.
Calculator.ShowCalculator();
}
}
}
Step 11 : Run application (Press
F5)->Click on show calculator.
Now you will see calculator window in your LightSwitch application.