More Stories

Nov 30, 2012

Silverlight: Access template control programmatically

by
If you are working on a Silverlight application, it's very imperative that you will end up wanting to assess a control from a design template.

If let's say I have a template where a CheckBox control is defined and if I want to access this control in my code behind, there is no direct way to do it.

... <ControlTemplate ..> <Grid>... <CheckBox x:Name="chkAll" .../> </Grid> </ControlTemplate /> ...
The following method will recusively look for this control  hiding anywhere in the control template against its name and return it when found.

  private object GetChildControl( DependencyObject parent, string  name)
  {
       Object  control = null ;
       int  count = VisualTreeHelper.GetChildrenCount(parent);
       for  (int  counter = 0; counter < count; counter++)
       {
           control = VisualTreeHelper.GetChild(parent, counter);
           //name supplied then Return Control if the control name matches  
           if  ((control as  DependencyObject).GetValue(NameProperty).ToString() == name)
               return  control;
           else  //Search Recursively if not found
           {
               control = GetChildControl(control as  DependencyObject, name);
               if  (control != null )
                         return  control;
           }
       }
             return  null ;
   }
 

You can get the reference of the control searching against its name.
CheckBox checkBox = (CheckBox)GetChildControl(this,"chkAll");


Dec 19, 2011

A simple jQuery slideshow

by
I have used jQuery animate() method to create a simple slideshow. I am toggling the opacity of the image from 0 to 1 and also changing the URL of the image. 

Script:

<script type="text/javascript">
function AnimateImg()
{

    var imgUrls = new Array("picture1.png", "picture2.png", " picture3.png ");
    var opacVal = 0;
    var currentImage = imgUrls[0];
    var index = 0;
    var DELAY = 1000;
    setInterval(function()
            {
            $("#animate-img").animate({ opacity: opacVal }, DELAY, function() {

                    if (opacVal == 0) {
                        opacVal = 1;
                    }
                    else {
                        opacVal = 0;
                    }

                    if (index == imgUrls.length) {
                        index = 0;
                    }

                    if (opacVal == 0) {
                        currentImage = imgUrls[index++];
                        $("#animate-img").attr("src", currentImage);
                    }
                });

            }, DELAY
       );
}
</script>
HTML:


<image id="animate-img" src="" style="height:200px"/>

DEMO:

Also check the jquery modal dialog here.

Dec 12, 2011

A jQuery modal wait dialog

by
The jQuery UI modal dialogs are great add-ons but they don’t necessary fit well when you just have to show a wait message. There are issues with removing the title bar and styling the dialog. BlockUI is another alternative but I find it little hard to style using css.

This is how I came up with a wait dialog. I am using two divs here. 
First div will cover the page content in such a way that the content is still visible but user cannot perform any action. For this, I need a div with near transparent background (opacity of 0.8)

  
   #loading-div-background 
    {
        display:none;
        position:fixed;
        top:0;
        left:0;
        background:black;
        width:100%;
        height:100%;
     }


The second div will contain an animated image and it can be positioned centrally in the page.

  
   #loading-div
    {
         width: 300px;
         height: 200px;
         background-color: #0c0b0b;
         text-align:center;
         position:absolute;
         left: 50%;
         top: 50%;
         margin-left:-150px;
         margin-top: -100px;
     }


Script

  
<script type="text/javascript">
        $(document).ready(function () {
            $("#loading-div-background").css({ opacity: 0.8 });
           
        });

        function ShowProgressAnimation() {
           

            $("#loading-div-background").show();

        }

    </script>


I am assigning the opacity property through jQuery css() funtion as it will take care of any browser compatibility issues.
Also, I have written a method which will bring up the background div. This can be invoked during form submit or whenever it is desired to block the page content. In this demo, I am triggering through a button click event.

HTML

  
<button id="show" onclick="ShowProgressAnimation();" >Show dialog</button>

<div id="loading-div-background">
    <div id="loading-div" class="ui-corner-all" >
      <img style="height:80px;margin:30px;" src="images/loading.gif" alt="Loading.."/>
      <h2 style="color:gray;font-weight:normal;">Please wait....</h2>
     </div>
</div>



Demo


Loading..

Please wait....

Also check the jQuery image slide show here.

Nov 24, 2011

Android PC ??

by
Looks like you will be carrying your PC in your pocket. A company has built a USB which connects your andriod phone to a display panel through HDMI interface. You can also connect it to your PC and android will appear as your virtualized desktop.

Jul 22, 2011

TFS Build Error Copying Silverlight XAP file

by
I was trying to automate build for Silverlight project using Team Foundation Server and build was failing with the following error.

Copying my.xap file failed. Access to path '..' denied.

Digging deep in the build log, I found that this is happening while copying the source files from TFS to the build folder for compilation. Since xap is an output file it is not required during the compilation. I avoided the download/copy of the xap file by denying access to the build agent. The steps are mentioned here.

May 6, 2011

Specifying Reference Paths in TFS 2010 build definition

by
While creating build definition using TFS 2008, we could specify the path(s) where the build server could look for the references. This was of great help as it avoided installing dependent assemblies in the GAC in the build server.
It was easily done by editing the project file and adding <AdditionalReferencePath> element.

In Team Foundation Server 2010, the build definition are workflow based and if you are creating any build definition using default template, there is no option to specify the additional reference paths.

Since, new template also supports the msbuild arguments, we have to specify the reference path as a build argument. For this we have to add "ReferencePath" as property to the msbuild arguments.

Go to Team Explorer >> Build Defintion >> Edit Build Definition >> Process >> Advanced Section >> MSBuild Arguments and Add the following: /p:ReferencePath=”{File path}”

We can specify multiple reference paths separated by ';'

Mar 4, 2011

The type 'System.Xml.IXmlLineInfo' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'

by
I have been getting this weird exception out of nowhere while compiling my solution. Turns out I had two projects in my solution using different System.Xml assembly. One using straight from .NET Framework 2.0 and other using assembly 2.0.5.0. ( from Silverlight runtime).

Referenced path were
C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll
&
C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Xml.dll respectively.

If a project file does not specify the exact reference assembly, compiler tries to use any matching assembly present in its cache. I could see the following reference in my csproj file.
<Reference Include="System.Xml"/>

I updated this reference with the correct version (along with the PublicKeyToken and Culture info) and made the SpecificVersion=True, enforcing compiler to use the specified assembly

<Reference Include="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>True</SpecificVersion>
<HintPath/>
</Reference>

This resolved my problem. Specifying strong references in project files will eliminate issues caused by same name assemblies.

Dec 13, 2010

Silverlight Developer runtime not installed

by
I have been getting "Silverlight Developer runtime not installed" message while trying to debug Silverlight 4 applications in VS2010 though I have installed the SDK. Seems this runtime is different installation altogether. You can install it from http://go.microsoft.com/fwlink/?LinkID=188039

Dec 10, 2010

Sporadic 'ORA-01001 Invalid cursor' error in Oracle 11g

by
According to the Oracle documentation,

" The ORA-01001 error occurs when:
A host language program call gave an invalid cursor for use
The value of the MAXOPENCURSORS option in the precompiler command was too small

You can fix the ORA-01001 error by:

  1. Checking your problematic call statement for any issues
  2. Specifying a correct LDA area or open the cursor as required
  3. Increasing the MAXOPENCURSORS option value before precompiling


As a note, the ORA-01001 error does not exist in Oracle 10g"

After debugging for almost a day following the above hints, I came to realise there is nothing wrong with my PL/SQL or with the configuration settings.

Sporadic "ORA-01001: invalid cursor" error occurs in Oracle 11g if there are RAM memory issues on the server.

If the same client call works once and fails the other minute with this error, you can check the server for memory issues before debugging further.

Nov 18, 2010

Windows Sleep command

by
I have a really long bat file where I need to introduce delay between subsequent commands. But there is no sleep command in DOS. There is an workaround for this, we can use ping command to emulate sleep.

Usage ping 1.1.1.1 -n 1 -w 10000

switch -n specifies number of echo request to be sent.
switch -w specifies number of milliseconds to wait for each reply.

Feb 4, 2010

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode

by
If you get this wierd error message while hosting your application in IIS 7.
Do not freak out, nothing is wrong with your settings. It's just that your code is an old timer. Changing the Managed pipeline mode to classic will solve your problem.

Nov 12, 2009

Public Key Token of an assembly

by

There are times when you need to get the public key token of an assembly. Okay the only time is when you need to put in config files. The answers is same old sn.exe. That's right the same .NET strong name tool we use to generate snk files.

Usage:
sn -T helloWorld.dll
This gives you the public key token of the strong named assembly.

Just wanted to share.

Apr 25, 2009

Passing parameters to a function in setTimeout()

by
While working on some 'animation' effect on one of my pages, I came across a problem when using setTimeout(). I am using it to call a function repeatedly in certain interval. I am not much into javascript so had quite a trouble figuring it out. If the function which is being called does not have any input parameters,
setTimeout(MyFunc(),10); // calls 'MyFunc' function every 10 ms.
But my 'Animate' function takes a parameter ( divId ),so I tried
setTimeout(Animate(divId),10); // wrong !!
This did not work.
The correct way to call a function with parameters in setTimeout function is.
setTimeout(function(){Animate(divId);}, 10);
This concept is called 'Closure' in javascript.
Just wanted to share...
Older Posts

Top Ad 728x90

Top Ad 728x90