Send email from Windows Phone

Sometimes an app need to send some information via email. To reach this gol a programmer need to write a few lines of code.

First of all, we can create a button and attach the Click event to send email. After that, in this event we call the EmailComposeTask and thats all.

Now we can build our email with the usual parameters (To, Subject, Body) and then we send the email.

EmailComposeTask email = new EmailComposeTask();
if ("<email_address>" != string.Empty)
{
     email.To = "<email_address>";
     email.Subject = "Subject message";
     email.Body = "Body message";
     email.Show();
}
else
{
     MessageBox.Show("Some error occours.", "WARNING", MessageBoxButton.OK);
}
Advertisements

Open web browser directly from your application

Sometimes we have the necessity to open web browser from own application to referencing something on the web.

To raise this gol we need for example to add the click event to a button and write few lines of code:

private void Button_Click(object sender, RoutedEventArgs e)
{
    WebBrowserTask wtb = new WebBrowserTask();
    wtb.Uri = new Uri("https://aaccostatech.wordpress.com/", UriKind.Absolute); 
    wtb.Show();         
}

That’s all! The web page will be appear in a few seconds

Create a simple Live Tile

One of the most striking features of the new MS Windows Phone OS are Live Tiles. Customizing your application tile is the argument of this post.

In a few lines of code we can build our custom tile.

The idea is to show, in the back content, the last inserted measure in the application. The application is Pressure Diary, shown in Windows Phone Applications page

public void CreateApplicationTile()
        {
            var appTile = ShellTile.ActiveTiles.First();

            if (appTile != null)
            {
                var standardTile = new StandardTileData
                {
                    Title = App.ApplicationName,
                    BackgroundImage = new Uri("Images/Tile_173x173.png", UriKind.Relative),
                    Count = null, // any number can go here, leaving this null shows NO number
                    BackTitle = App.ApplicationName,
                    BackContent = "Last measure: " + "[" + this.globalMeasure.Systolic.ToString() + "/" + this.globalMeasure.Diastolic.ToString() + "]" + this.globalMeasure.Date.Value.ToShortDateString()
                };

                appTile.Update(standardTile);
            }
        }

You can use these line of code to build your custom tile.