Here we will see how to use the Property Changed Event by developing a LightSwitch Application (Visual C#) in Visual Studio 2012.
The following is the procedure for using the Property Changed Event in LightSwitch 2012.
Step 1
Open the Solution Explorer.
![sol ex.jpg]()
Step 2
In the Solution Explorer, right-click on the Server and choose "Add Table".
![Add Table.jpg]()
Step 3
The table appears.
![stu table.jpg]()
Step 4
In the table select the "WayOfEntry" field.
![entryrow.jpg]()
Now go to the property window and select "Choice List".
![prop.jpg]()
Define the following choices for the property and click the "OK" button.
![choicelist.jpg]()
Step 5
In the Solution Explorer, right-click on the Screens and choose "Add Screen".
![add src.jpg]()
Step 6
The Add New Screen dialog box appears. Select "New Data Screen" from the Screen Templates, under screen information, choose "Student" under screen data and provide a name for the screen and click the "OK" button.
![src.jpg]()
Step 7
The Screen Designer appears for the New Data Screen.
![app desi.jpg]()
From the screen designer select "HighSchoolPercentage" and then go to the property window and uncheck the "Is Visible" checkbox.
![chkbox not visible.jpg]()
Step 8
Now we are going to create a new group for these two fields.
![NewGroup.jpg]()
Add the following fields to this group:
![complete src desi.jpg]()
Step 9
In the menu bar, select on Write Code a drop down list will appear and from that list select the _created() method and provide the following code:
![_Created.jpg]()
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.ComponentModel;
namespace LightSwitchApplication
{
public partial class CreateNewStudent
{
partial void CreateNewStudent_InitializeDataWorkspace(global::System.Collections.Generic.List<global::Microsoft.LightSwitch.IDataService> saveChangesTo)
{
// Write your code here.
this.StudentProperty = new Student();
}
partial void CreateNewStudent_Saved()
{
// Write your code here.
this.Close(false);
Application.Current.ShowDefaultScreen(this.StudentProperty);
}
partial void CreateNewStudent_Created()
{
// Write your code here.
Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() =>
{
((INotifyPropertyChanged)this.StudentProperty).PropertyChanged += new PropertyChangedEventHandler(CreateNewStudent_propChanged);
});
}
private void CreateNewStudent_propChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName.Equals("WayOfEntry"))
{
if (this.StudentProperty.WayOfEntry.Equals("Re"))
{
this.FindControl("HighSchoolPercentage").IsVisible = true;
this.FindControl("InterPercentage").IsVisible = false;
}
else
{
this.FindControl("HighSchoolPercentage").IsVisible = false;
this.FindControl("InterPercentage").IsVisible = true;
}
}
}
}
}
Step 10
Press F5 to run the application.
![output1.jpg]()
As we select the regular option, the HighSchool Percentage control is available.
![output2.jpg]()
Similarily, when we select the corresponding option, the Inter Percentage control is available.
![output3.jpg]()