Monday, June 28, 2010

Implementation of IValueConverter Interface.

Arvind (Silverlight,.NET,C#): Implementation of IValueConverter Interface.

Implementation of IValueConverter Interface.

I have done small experiment on IvalueConverter in Silverlight.
So,I am presenting here my small experiment.


I am giving a small sample code for IvalueConvert interface and how can we implement in binding(XAML).

Suppose, I want to convert/format date time in side a datagrid or in textbox while binding.
Todo this we have to follow three steps.

Step 1: Create a class , (here I am giving name it as DateConverter.) and implement interface IvalueConverter.


public class DateConverter : IValueConverter
    {
        public object Convert(object value,
                              Type targetType,
                              object parameter,
                              System.Globalization.CultureInfo culture)
        {
DateTime date = (DateTime)value;
            return date.ToString(parameter.ToString());
        }
public object ConvertBack(object value,
                                  Type targetType,
                                  object parameter,
                                  System.Globalization.CultureInfo culture)
        {
            string strValue = value.ToString();
            DateTime resultDateTime;
            if (DateTime.TryParse(strValue, out resultDateTime))
            {
                return resultDateTime;
            }
            return value;
        }
}

these two methods( Convert & ConvertBack) will take four parameters.

Step 2: Add class reference to XAML.

  xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:c="clr-namespace:SilverlightApplication6"
    Width="400" Height="300">
   
        //Adding name space of class reference.
   

   
  
                     
   




Step 3: Binding data to textblock using InotyfypropertyChanged.
public class Customer : INotifyPropertyChanged
    {
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private DateTime _birthday;
public DateTime Birthday
        {
            get { return _birthday; }
            set
            {
                _birthday = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Birthday"));
                }
            }
        }

}
.


aravindbenator@gmail.com

Thursday, June 24, 2010

Interaction between two XAP's in silverlight!

In many of the cases we need to communicate between the XAP's internally.Suppose if we want to use reuse silverlight application then we have to make it available for communicate.

So, In this way if one xap file wants to communicate with other xap file, have to use javascript to invoke communication.


1.Step:Registering managed object using RegisterScriptableObject.

HtmlPage.RegisterScriptableObject("ARV", this);
this ARV name will be used on later with javascript.

Invoking javascript function from silverlight.
HtmlPage.Window.Invoke("TalkToJavaScript", "Hello from Silverlight");

2.Step:

C# method to get value from previous XAP.

[ScriptableMember]

public void UpdateText(string result)

{

myTextbox.Text = result;

}


3.Step: javascript function.



function TalkToJavaScript( data)

{

alert("Message received from Silverlight: "+data);



var control = document.getElementById("silverlightControl");

control.Content.Page.UpdateText("Hello from Javascript!");

}




Mail To:aravindbenator@gmail.com

Wednesday, June 9, 2010

Color Animation in silverlight

1.Creating storyboard object.

private Storyboard str_board= new Storyboard();

2.Creating coloranimation object.
On the next line, declare a new ColorAnimation object called BlueColor:

private ColorAnimation BlueColor = new ColorAnimation();

3.Setting Targetname and TargetProperty to the storyboard.


BlueColor.SetValue(Storyboard.TargetNameProperty, "MyEllipse");
BlueColor.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(Shape.Fill).(SolidColorBrush.Color)"));

4.Change to new color.

Color ToColor = Color.FromArgb(255, 13, 8, 116);
BlueColor.To = ToColor;


5.The animation can now be added to the storyboard, and the storyboard added to the LayoutRoot element:

TurnsBlue.Children.Add(BlueColor);
LayoutRoot.Resources.Add("TurnsBlue",TurnsBlue);

Aravindbenator@gmail.com

Monday, June 7, 2010

Sharing view on Asp.net process model

Asp.net process model:
We can devide asp.net request processing in 3 states.

State 1:
When a request arrives,IIS examines the resource type and calls into ASPnet_ISAPI extension.Later it will pass into the actual worker process(aspnet_wp.exe).If current process is already enabled (i.e it's working or serving a request), aspnet_isapi queues the request and assignes it the worker process later.

State 2:
After recieving a request,ASPnet worker process notifies the aspnet_isapi that "it is serving a request" .aspnet_isapi maintains state reference internally.When ISAPI recieves this message from process, it will mark status as "Executing". Each worker process can handle single request at a time.

It will use synchronous model,because as i already stated above worker process can't start processing request which is not yet marked as "executing" in the ISAPI internal table.

ASPNET_Wp also able to start new process, when suppose existing one consuming too memory, and responding too slowly.Also it can automatically assign pending request to existing other process.

State 3:

When finished,the response is sent to aspnet_ISAPI.the state of the request has been changed to "DOne" in ISAPI internal table.Later on request state has been removed from thae table.If worker process crashes,executing state in ISAPI will remains same. When aspnet_ISAI detects,that the proces is dead it will removes the sate from ISAPI and frees all the IIS associted resources.



Aravindbenator@gmail.com