Windows Phone Developers

Thursday, March 14, 2013

How to Load Image On The Fly using C#.NET on Windows Phone Content Control

How to Load Image (PNG/JPG/BitMap) On The Fly using C#.NET on Windows Phone Content Control
How to add Controls to Phone Page in RunTime




There are many times you want to load the Image through code instead of the design time. The following snippet allows you to assign an Image available in the Project to the content control.



public void LoadImage()
        {
            string sFilePath = "/Images/Thiruvanamalai BackGround.png";

            Uri uriImage = new Uri(sFilePath,UriKind.Relative );
            Image  imgBackGrnd = new Image();
            imgBackGrnd.Source = new BitmapImage(uriImage);
            
            imgBackGrnd.Height = 200; //Set the Height and Width of the Image
            imgBackGrnd.Width = 200;
            imgBackGrnd.Stretch = Stretch.Fill; 
            ContentPanel.Children.Add(imgBackGrnd);

        }


Assigning Relative Path of URL

The code below assigns the Path of the Image, UriKind implies if it is relative / absolute

Uri uriImage = new Uri(sFilePath,UriKind.Relative );


The assigned image is shown below:


 
 
See also:
 
 
 
 
 
 
 
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment