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:
No comments:
Post a Comment