CodeBehind vs CodeFile

Posted: June 12, 2014 in ASP.Net

CodeBehind
Needs to be compiled and the compiled binary is placed in the bin folder of the website.

<%@ Page Title="" Language="C#" MasterPageFile="~/YourMasterPage.Master" AutoEventWireup="true" CodeBehind="YourFile.aspx.cs" Inherits="YourPage" %>

CodeFile
You provide the source file with the solution for deployment and .NET compiles the code when needed.

<%@ Page Title="" Language="C#" MasterPageFile="~/YourMasterPage.Master" AutoEventWireup="true" CodeFile="YourFile.aspx.cs" Inherits="YourPage" %>

To play , you can try the following:

sing Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework;
using System.IO;

Stream stream = TitleContainer.OpenStream("MySoundFile.wav");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();

To make a windows phone device vibrate, you can try the following:

using Microsoft.Devices;

VibrateController vibrate = VibrateController.Default;
vibrate.Start(TimeSpan.FromMilliseconds(1000));

Convert String to TimeSpan

Posted: March 15, 2012 in ASP.Net

To convert a String to TimeSpan, you can try the following:

TimeSpan myTimeSpan = TimeSpan.Parse("00:00:30");

To get a t of all songs from your Media Library and bind it to a ListBox control, first add the control in your XAML file as follows:

<ListBox x:Name="myListBox" />
using Microsoft.Xna.Framework.Media;

private void ListSongs()
{
  MediaLibrary myLib = new MediaLibrary();
  var mySongName = (from m in myLib.Songs select m.Name).ToList();
  myListBox.ItemsSource = mySongName;
}

Disable Lock Screen

Posted: March 14, 2012 in Windows Phone 7 & Mango

If you need to disable the lock screen while your app is running, you can try the following:

using Microsoft.Phone.Shell;

PhoneApplicationService phoneAppService = PhoneApplicationService.Current;
phoneAppService.UserIdleDetectionMode = IdleDetectionMode.Disabled;</code>

It is a good idea to add a Review My App button to your windows phone applications To do this, you can simply add the following to any button click event handler:

using Microsoft.Phone.Shell;
if (PhoneApplicationService.Current.State.ContainsKey("KeyName"))
{
  // Do something
}

It is a good idea to add a Review My App button to your windows phone applications To do this, you can simply add the following to any button click event handler:

using Microsoft.Phone.Tasks;
MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();
marketplaceReviewTask.Show();

To convert a color to a brush, you can do the following:

Brush myBrushColor = new SolidColorBrush(Colors.Red);

If you have multiple TextBox controls on you screen, you might want the user to just press the enter key on the virtual keyboard to tab between them. To do this. you need to capture the KeyDown event of the control as follows:

<TextBox x:Name="TextBox1" InputScope="Text" KeyDown="TextBox1_KeyDown"/>
<TextBox x:Name="TextBox2" InputScope="Text" KeyDown="TextBox2_KeyDown"/>
<TextBox x:Name="TextBox3" InputScope="Text"/>

Now in the code behind file you can handle the navigation as follows:

private void TextBox1_KeyDown(object sender, KeyEventArgs e)
{
    if(e.Key.Equals(Key.Enter))
    {
        TextBox2.Focus();
    }
}

private void TextBox2_KeyDown(object sender, KeyEventArgs e)
{
    if(e.Key.Equals(Key.Enter))
    {
        TextBox3.Focus();
    }
}