Windows Phone Developers

Showing posts with label Windows Phone Development. Show all posts
Showing posts with label Windows Phone Development. Show all posts

Tuesday, June 18, 2013

Windows Phone Development : How to Create HyperLinks to External Sites / Pages using Silverlight XAML

How to Link External Websites to Windows Phone Pages using C#/VB.NET

Once you create a  +Windows Phone application with content, you will have a necessity to link it to multiple websites (External etc).

You can use either HyperlinkControl or the Hyperlink XAML Tag to achieve that.

Let's take our Sample App (refer QR Code) which has a good list of Hotels and Restaurants.

The App tries to provide links to these websites.

Adding Hyperlink Tag to the Content/Grid should help.

Exceptions while Adding Hyperlink / Navigating Hyperlink in Windows Phone Application

{"Cannot navigate to locations relative to a page."}


{"Navigation is only supported to relative URIs that are fragments, or begin with '/', or which contain ';component/'.\r\nParameter name: uri"}

The above exceptions are caused when the TargetName is not set to _blank

(or)

The http:// prefix is omitted in NavigateUri

The correct representation is given below:

<Hyperlink TargetName="_blank" NavigateUri="http://www.hotelnalaresidency.com">www.hotelnalaresidency.com</Hyperlink>

The +Silverlight code worked perfectly bringing the Website as shown below 

See also:

Hyperlink Control in Windows Forms (VB.NET) Application

How to Download File from Website using C# (.NET)

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

Monday, June 17, 2013

How to Add/Load XAML Dynamically to RichTextBox Control - Windows Phone Development C#/VB.NET

Windows Phone Development - Populate RichTextBox Content from External XAML File / How to Read Content from External Resource File


+Windows Phone Developers are under pressure to release many updates time to time. Please have a look at the sample application that we have been asked to develop. This particular application is about Tiruvannamalai which houses Ashrams of +yogi ram suratkumar , +Ramana Maharshi , +seshadri swamigal and famous for +Girivalam tiruvannamalai .


This place was known to western world, thanks to Paul Brunton. His book - A Search in Secret India: The Classic Work on Seeking a Guru  was a best seller

Okay, we have diverted a lot. This particular application requires lot of content. A look at the App should make you understand. Have tried the following method to separate the content from XAML file and link it when necessary



Here is how it works:

  • Create Content
  • Embed As Resource
  • Create Place Holder (RTB)
  • Retrieve Resource
  • Assign to Control
 
 
 
Creating content is not an easy task. But beyond the scope of our post. Once the content is created, it has to be embedded as a resource file

Create the XAML for the content and save it as a text file and add it to the project's Resource
 
 
 

 
 
 

 
 


Ensure that the Resource is BuildAction is set to Embedded Resource. Once that is completed use +C# or +Visual Basic.NET code
the following code to get the XAML assigned to the RichTextBox using

How to Read the External ResourceFile using .NET (C#/VB.NET)

GetManifestResourceStream method is used to get the content from the embedded file as a string

private void GetXAML()



{
RichTextBox rtb = this.PageContent;

string result = "";

using (Stream stream = Assembly.GetExecutingAssembly()

.GetManifestResourceStream("Tiruvannamalai.Resources.PageContentXAML.txt"))

using (StreamReader reader = new StreamReader(stream,System.Text.Encoding.UTF8))



{

result = reader.ReadToEnd();



}
string xamlOP = @"
"
;

string xamlMid = result;

string xamlCL = "
";


rtb.Xaml = xamlOP + xamlMid + xamlCL ;

}

The Content is sandwiched between Section tags (here as separate variables) and populated dynamically to the Windows Phone. I tested this using +Nokia Lumia 710 and looks good.

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

Monday, May 13, 2013

How to Track Page (Pivot Item) Navigation in Windows Phone using .NET (C#) / Windows Phone Pivot Control Events (C#/.NET)

Pivot_Change /SelectionChange  / Page Change Event in Windows Phone using .NET

One of the commonly used Windows Phone Application Type is Pivot. A Pivot application has a Pivot control and many Pivot Items in it.
This gives a good look and feel for content rich App


How to track Pivot Item Change

Each Pivot item contains some unique information, which makes it a necessary for tracking the change of Windows Phone Pivot Items

The XAML of the Pivot Control is shown below

 <controls:Pivot Title="GNANA BHOOMI - TIRUVANNAMALAI" SelectionChanged="Pivot_SelectionChanged>;





The Pivot_SelectionChanged event can be used to track the flip / change of Pivot Item to a new one by the user


private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)



{
 
MessageBox.Show(((Pivot)sender).SelectedIndex.ToString());



}

SelectedIndex property provides the Index of the active Pivot Item
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, 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

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