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

Wednesday, March 13, 2013

How to Add App, BackGround and SplashScreen Images to Windows Phone

C# - Add Title and Tile images to Windows Phone


Windows Phone primary contains the following Application images

Application - This image is shown as Icon for Application
BackGround - This will be used in Tile
SplashScreen - This image will be shown during loading of the application

The images for Application and Background can be set from Properties Dialog:




The Size of the images are

Application - 62    X  62
Background - 173 X  173
SplashScreen - 480 X 800 (should be JPG)

The default Star Icon will be added to the project automatically from Visual Studio

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

Thursday, July 26, 2012

C# .NET Images / Icons as Resources and Content

Build Action Resources vs Content in .NET / C# .NET Images / Icons as Resources and Content

Images can be added either as a Resource or Content Resource - This is default for Images / Icons Content - The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file.



Having Images as Content will reduce the Filesize. Having as a Resource appears to load the images faster .. it might be my perception. Please express your views on it 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

How to Add Icons to the Windows Phone Project (C#/.NET)

Windows Phone SDK comes with a list of Icons.

They are available in the following location

 Location of Icons in Visual Studio (Windows Phone Development):

On 32-bit operating systems: C:\Program Files\Microsoft SDKs\Windows Phone\v7.1\Icons On 64-bit operating systems: C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Icons

To add an icon to the project: Icons can be either created or added;

If you want to create a new Icon
 file use the following option

To add an existing icon, select from the list of Icons
 
Do some edits / updates if needed

Set the set the Build Action to Content.
            would
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

How to Enable ApplicationBar on Windows Phone (XAML)

How to enable Application Bar in Windows Phone Application using .NET The Application bar is available in the XAML file. It is commented by default. Remove the commented section and use the Application Bar in your App The ApplicationBar can be customized 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

Sunday, May 6, 2012

Using Directive in C#, Create an alias in C#

Before you can use the classes in a given namespace in a C# program, you must add a using directive for that namespace to your C# source file. In some cases, you must also add a reference to the DLL that contains the namespace


The using directive has two uses:
· To allow the use of types in a namespace so that you do not have to qualify the use of a type in that namespace:


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

· To create an alias for a namespace or a type.

using Excel = Microsoft.Office.Interop.Excel

The using keyword is also used to create using statements, which help ensure that IDisposable objects such as files and fonts are handled correctly. See using Statement for more information.
The scope of a using directive is limited to the file in which it appears.
Create a using alias to make it easier to qualify an identifier to a namespace or type.

Big Statements like the following

oXL = new Microsoft.Office.Interop.Excel.application();

can be replaced with

using Excel = Microsoft.Office.Interop.Excel
oXL = new Excel.application();

Create a using directive to use the types in a namespace without having to specify the namespace. A using directive does not give you access to any namespaces that are nested in the namespace you specify.
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

Calculating Time taken for an operation using VB.NET (in Milliseconds)

Calculate Processing Time for a Vb.NET Subroutine (accuracy to millisecond)


Not every project will have the luxury of having rational analyzer to check the process time for every subroutine/function. In those cases we can use the StopWatch to determine the time taken for a program

Imports System.Diagnostics

Sub Get_Accurate_ProcessTime()

Dim oWatch As New Stopwatch

oWatch.Start()

Process_database()

oWatch.Stop()

MsgBox("Total Time Taken for Database Operation := " & oWatch.ElapsedMilliseconds.ToString)


End Sub
A Stopwatch instance can measure elapsed time for one interval, or the total of elapsed time across multiple intervals. In a typical Stopwatch scenario, you call the Start method, then eventually call the Stop method, and then you check elapsed time using the Elapsed property.
A Stopwatch instance is either running or stopped; use IsRunning to determine the current state of a Stopwatch. Use Start to begin measuring elapsed time; use Stop to stop measuring elapsed time. Query the elapsed time value through the properties Elapsed, ElapsedMilliseconds, or ElapsedTicks. You can query the elapsed time properties while the instance is running or stopped. The elapsed time properties steadily increase while the Stopwatch is running; they remain constant when the instance is stopped.


By default, the elapsed time value of a Stopwatch instance equals the total of all measured time intervals. Each call to Start begins counting at the cumulative elapsed time; each call to Stop ends the current interval measurement and freezes the cumulative elapsed time value. Use the Reset method to clear the cumulative elapsed time in an existing Stopwatch instance.
The Stopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time. Otherwise, the Stopwatch class uses the system timer to measure elapsed time. Use the Frequency and IsHighResolution fields to determine the precision and resolution of the Stopwatch timing implementation.


The Stopwatch class assists the manipulation of timing-related performance counters within managed code. Specifically, the Frequency field and GetTimestamp method can be used in place of the unmanaged Win32 APIs QueryPerformanceFrequency and QueryPerformanceCounter.
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