Showing posts with label c sharp. Show all posts
Showing posts with label c sharp. Show all posts

Delegates in C#


Delegates
  • It is a reference type, holds address of a method.
  • Allows to change reference to a method at runtime.
  • Referring method should have the return type and function signature same as that of the delegate. 

  •  The following are the steps for implementing Delegates
o   Declare a delegate
*  Syntax
[access modifier] delegate <return type> <delegate name> <parameter list>
*  E.g.
public delegate void MyDelegate();
*  This delegate can refer any method having no parameter with no return type.
o   Instantiate a delegate
*  MyDelegate delObj = new MyDelegate(staticMethod);
*  delObj is an object of type MyDelegate
*  delObj refers to staticMethod, by passing the name of method to the delegate constructor.
o   Invoke a delegate
*  Delegates are invoked using its object name and passing the parameters, if required, in a similar way of calling methods.
*  delObj();
  • Types of Delegate
o   Single-cast Delegate
*  Refers to only one method at a time.
o   Multicast Delegate
*  A single delegate can refer to multiple methods.
*  Contains an invocation list of multiple methods.
*  Invokes multiple methods provided all methods have same return type and same function signature.
*  When invoked, executes the referenced methods in the calling order.

DOWNLOAD SAMPLE CODE: CLICK HERE

Page Navigation in Silverlight

  • Navigation in Silverlight from one page to another is done on Frame.
  • Below example will explain how to navigate between pages in Silverlight.
Result  has been displayed below..  Dont Forget to download Source Code for your Reference

On Button Click of Page 1


 On Button Click of Page 2


Xaml Page Code For Page Navigation :



Xaml.cs Code For Page Navigation :


  • Line Series Chart comes with the Silverlight 4 Toolkit.
  • The Chart control is stored in the Microsoft.Windows.Controls.DataVisualzation.Charting assembly. This assembly can be referenced just like any other assembly in Visual Studio.  
 Result  has been displayed below..  Dont Forget to download Source Code for your Reference

Xaml Page Code For Line Chart Series :


Xaml.cs Code For Line Chart Series :


  • Pie Chart Series comes with the Silverlight 4 Toolkit.
  • The Chart control is stored in the Microsoft.Windows.Controls.DataVisualzation.Charting assembly. This assembly can be referenced just like any other assembly in Visual Studio.  
 Result  has been displayed below..  Don't Forget to download Source Code for your Reference


Xaml Page Code For Pie Series :



Xaml.cs Code For Pie Series :




  • Column Series Chart comes with the Silverlight 4 Toolkit.
  • The Chart control is stored in the Microsoft.Windows.Controls.DataVisualzation.Charting assembly. This assembly can be referenced just like any other assembly in Visual Studio.  
Result  has been displayed below..  Dont Forget to download Source Code for your Reference

Xaml Page Code For Chart Series :



Xaml.cs Code For Chart Series :


Download Source Code : Click here to download Source Code of Column Chart Series in Silverlight
DataGrid Binding in Silverlight

Result of the Program has been shown below.
Here we bind Each Column to display respected data in Grid.
Detailed Information is given below and dont forget to Download Source Code for Reference.


Xaml Page Code :
Xaml.cs Code :



Download Source Code : Click here to download Source Code of Data Grid binding in Silverlight

Binding Date Picker in Silverlight

Today we are going to learn how to bind Date Picker in Silverlight .. Lets start with it ..
Below shown is a result of data binding of Date picker in Silverlight.




Xaml Page Code shown below of date picker :

Here SelectedDate Property of Date Picker has been binded to get desired result.

Xaml.cs Page Code :


 Binding Date Picker in Silverlight

Binding of Combo Box in Silverlight on Selected Index Property of Combo Box 

Xaml Code for binding Combobox :

Xaml.cs Code for binding Combobox :



Output Result of data binding of Combo box :

Thus we have succesfully Binded selected item property of combo box in silverlight.


Simple Animation in Silverlight





Simple Animation Example in Silverlight has been Explained below with Source Code to download




Xaml Code :-



Xaml.cs Code :-





Alternate way to Disable a Button in Silverlight.


So to avoid this blur Effect we can use other Properties of Button in Silverlight to Disable it. 


XAML Code to disable Button :-
<Button Content="A2z" IsHitTestVisible="False" Height="23" HorizontalAlignment="Left" Margin="170,146,0,0" Name="MY_BUTTON" VerticalAlignment="Top" Width="75" />





 BackEnd ( XAML.cs) Code to enable and disable Button at Runtime :-

 //button gets Disabled and Visibility of Button Remains same as in Enabled Mode.
  MY_BUTTON.IsHitTestVisible = false;
//button gets Enabled
  MY_BUTTON.IsHitTestVisible = true;





How to disable Silverlight Button Control ?



XAML CODE OF BUTTON (ENABLED) IN SILVERLIGHT : -
<Button Content="A2z" Height="23" HorizontalAlignment="Left" Margin="170,146,0,0" Name="MY_BUTTON" VerticalAlignment="Top" Width="75" />


XAML CODE OF BUTTON (DISABLED) IN SILVERLIGHT : -
<Button Content="A2z" IsEnabled="False" Height="23" HorizontalAlignment="Left" Margin="170,146,0,0" Name="MY_BUTTON" VerticalAlignment="Top" Width="75" />


BackEnd (XAML.cs) Code to Disable and Enable Silverlight Button at Runtime dynamically :-
 MY_BUTTON.IsEnabled = false; // button gets Disabled
 MY_BUTTON.IsEnabled = true; // button gets Enabled
top