Showing posts with label Silverlight Application.. Show all posts
Showing posts with label Silverlight Application.. Show all posts

Wednesday, 9 November 2011

Beware of recursion on getter/setter methods

Question Received:
      The Application is not responding apparently.

Solution:
     Check the code for any defects like recursion in the statement and methods.
     Defect I have found from the getter/setter methods.
     private string _mail;
     public string Mail
     {
          get
          {
               return _mail;
          }
          set
          {
              if(condition)
              {
                   Mail="mail@daemon.com";
              }
          }
     }
     public DataSource()
     {
          Mail="mail@daemon.com";
     }

[Note:]
The culprit is,
       In setter method, Mail="mail@daemon.com" makes it call the setter method recursively.

How to add the extender to Silverlight TextBox

Question Received:
         To add the extender to validate any value typed in the TextBox.

Solution:
        i. Create DataSource.cs which contains the getter/setter methods for evaluating the value in the TextBox.
        ii.Integrate it with the Page.xaml.cs using instance to point the DataContext in the LayoutRoot.
        iii.Bind the Data to the necessary controls (ie.,TextBox).
        iv.Throw the error on exception and make it to be caught from 'LayoutRoot'.
        v. Add the necessary handler in the 'page.xaml.cs'.
        vi.However, all the handlers will be coded in the 'page.xaml.cs'.
        vii.Alright, Compile and execute it will be working.
        viii.Download the detailed document from, ExtenderToSilverLightControls.docx.
        ix.Download the source from, SilverlightDataValidation.

[Note:]
    --> Make sure that the DataSource to initialize the value, that will not throw the error on Page_init() or page_Load().
    --> If so, silverlight application will not be starting.