• Wriju's BLOG

    Azure OData and Windows Phone 7

    • 0 Comments

    In this post I am planning to cover the topic where we will be exposing data in SQL Azure using WCF Data Services and consume it from Windows Phone 7.

    We have data available in SQL Azure. So we will create one let’s say and application ASP.NET MVC and add the Entity Framework data model there.

    image

    After we have added the model we will build the project and add one WCF Data Services file and modify the generated code as below,

    public class EmpDS : DataService<DBAzEntities>
    {
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }
    
        protected override DBAzEntities CreateDataSource()
        {
            DBAzEntities ctx = new DBAzEntities();
            ctx.ContextOptions.ProxyCreationEnabled = false;
            return ctx;
        }
    }
    

    After that upload it to the Azure Hosted services. Once that is done we now can view it in browser to check the validity of the URL. This would allow you to view your data in browser. After that we will build the Windows Phone 7 application to consume the data.

    Build Windows Phone 7 Silverlight application and add “Service Reference” pointing to the URL

    image

    After that write the below code to MainPage.xaml

    public DataServiceCollection<Emp> Emps { get; set; } 
    
    public void LoadData()
    {
        DBAzEntities ctx = new DBAzEntities(new Uri(@"http://127.0.0.1:81/Models/EmpDS.svc/"));
    
        Emps = new DataServiceCollection<Emp>();
        var query = from em in ctx.Emps
                    select em;
        Emps.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(Emps_LoadCompleted);
        Emps.LoadAsync(query);
    }
    
    void Emps_LoadCompleted(object sender, LoadCompletedEventArgs e)
    {
        lstData.ItemsSource = Emps;
    }
    

    And the corresponding XAML would look like,

    <ListBox x:Name="lstData" >
        <ListBox.ItemTemplate>
            <DataTemplate>                    
                <StackPanel>
                    <TextBlock Text="{Binding Path=FullName}"></TextBlock>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>            
    

    And the final output would look like

    image

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone Mango Development Jump Start available at Channel 9

    • 0 Comments

    Learn development in Windows Phone Mango with Rob Miles and Andy Wigley

    1. Mango Jump Start (01): Building Windows Phone Apps with Visual Studio 2010

    2. Mango Jump Start (02): Silverlight on Windows Phone—Introduction

    3. Mango Jump Start (03): Silverlight on Windows Phone—Advanced

    4. Mango Jump Start (04): Using Expression to Build Windows Phone Interfaces

    5. Mango Jump Start (05): Windows Phone Fast Application Switching

    6. Mango Jump Start (06): Windows Phone Multi-tasking & Background Tasks

    7. Mango Jump Start (07): Using Windows Phone Resources (Bing Maps, Camera, etc.)

    8. Mango Jump Start (08a): Application Data Storage on Windows Phone | Part 1

    9. Mango Jump Start (08b): Application Data Storage on Windows Phone | Part 2

    10. Mango Jump Start (09): Using Networks with Windows Phone

    11. Mango Jump Start (10): Tiles & Notifications on Windows Phone

    12. Mango Jump Start (11a): XNA for Windows Phone | Part 1

    13. Mango Jump Start (11b): XNA for Windows Phone | Part 2

    14. Mango Jump Start (12): Selling a Windows Phone Application

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone : Using Accelerometer in Emulator

    • 0 Comments

    If you are building application which is dependent on Accelerometer, then the Emulator allows you to test that. The below example was demonstrated on MIX11.

    Let’s suppose you have image and based on the X or Y axis of your phone image will rotate.

    <Image Height="428" HorizontalAlignment="Left" Margin="106,96,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="233" Source="/PhoneApp3;component/Images/Phone7.png" >
        <Image.Projection>
            <PlaneProjection x:Name="accImg" ></PlaneProjection>
        </Image.Projection>
    </Image>

    You need to add the assembly Microsoft.Devices.Sensors. After that

    Accelerometer _acc = new Accelerometer();
    public AccelrmtrDemo()
    {
        InitializeComponent();            
        _acc.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(_acc_ReadingChanged);
        _acc.Start();
    }
                   
    
    void _acc_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
    {
        Dispatcher.BeginInvoke(() =>
        {
            accImg.RotationY = -90 * e.X;
            accImg.RotationX = -90 * e.Y;
        });
    }
    

    Now you need to use the Emulator’s extender as below

    image

    And after that move the red pointer to have the feeling of actually moving the Windows Phone Device.

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : Choosing Photo from your Phone

    • 0 Comments

    You may choose photo from your phone through the application

    PhotoChooserTask MyPhotoChooser = new PhotoChooserTask();
    MyPhotoChooser.Completed += new EventHandler<PhotoResult>(MyPhotoChooser_Completed);
    MyPhotoChooser.ShowCamera = true;
    MyPhotoChooser.Show();

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : Sending SMS from your application

    • 1 Comments

    Sending SMS from application is as simple as below

    SmsComposeTask MySMS = new SmsComposeTask();
    MySMS.Body = "Hello from Mango";
    MySMS.To = "111111";
    MySMS.Show();

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : Choosing Email Application to send email

    • 0 Comments

    You may choose email application to send an email from your phone.

    EmailComposeTask MyEmailComposer = new EmailComposeTask();
                
    MyEmailComposer.To = "wriju@contoso.com";
    MyEmailComposer.Subject = "Mango Email";
    MyEmailComposer.Body = "Welcome to the Magic!!!";
                
    MyEmailComposer.Show();
    

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : Choosing Email address from the list

    • 0 Comments

    If you are composing a text and wanted to send it to the people listed in your contact you can choose from the list. Here is how you can do it.

    EmailAddressChooserTask emailAddress = new EmailAddressChooserTask();
    emailAddress.Completed += new EventHandler<EmailResult>(emailAddress_Completed);
    emailAddress.Show();
    And to capture the email address you can have this small code.
    void emailAddress_Completed(object sender, EmailResult e)
    {
    
        if (e.TaskResult == TaskResult.OK)
        {
            MessageBox.Show(e.Email.ToString());
        }
    }
    

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : Calling a Number from Application

    • 0 Comments

    Here is how we can launch the in-built phone and call a number specified by us.

    PhoneCallTask PhoneTask = new PhoneCallTask();

    PhoneTask.PhoneNumber = "1111111111";

    PhoneTask.Show();

    Namoskar!!!

  • Wriju's BLOG

    Partner Event : Windows Phone 7 Mango - Platform Overview for Application Development

    • 0 Comments

    I am happy to announce the upcoming event for Microsoft MPN Partner on

    Windows Phone 7 Mango - Platform Overview for Application Development

    Date & Time: Aug 29, 11 Pacific time via Office Live Meeting

    Registration: https://training.partner.microsoft.com/learning/app/management/LMS_ActDetails.aspx?UserMode=0&ActivityId=752004

    Presenter: Wriju Ghosh, Lead Partner Technical Consultant, Microsoft.

    Abstract: This session will walk you through the windows Phone Mango platform application development. Explore new platform features and to understand the next application development for it.

    See you all in the session.

  • Wriju's BLOG

    Windows Phone 7 : Invoke Bing Search

    • 1 Comments

    If you let people quickly open Bing search with the selected word while navigating your application in your Windows Phone 7.

    //Curtsey WP7 Training Kit - MUST HAVE IT!!!
    WebBrowserTask wbTask = new WebBrowserTask();
    string BingURL = @"http://m.bing.com/search?q={0}";
    string searchKeyword = textBox2.Text;
    wbTask.Uri = new Uri(string.Format(BingURL, searchKeyword), UriKind.Absolute);
    wbTask.Show();
    

    Namosakar!!!

  • Wriju's BLOG

    Windows Azure Free Whitepapers Updated

    • 0 Comments

    Note: You might need to register yourself before downloading. This will be prompted.

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : Open URL in IE9 from Application

    • 0 Comments

    Launching browser from your Phone application is often required. The common term could be “Shell” for those who came to classic VB age like me. Later in .NET it was wrapped under System.Diagnostic.Process. In Windows Phone 7 we might need such functionality while working with RSS kind of application where user can click on the link and open it in browser.

    WebBrowserTask wbTask = new WebBrowserTask();
    //URL = http://create.msdn.com
    wbTask.Uri = new Uri(textBox1.Text, UriKind.RelativeOrAbsolute);
    wbTask.Show();
    

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : Using Local Database for Application

    • 4 Comments

    Windows Phone uses concept of Local Database and by implementing LINQ to SQL you can create 100% relational database driven application.

    Windows Phone DataContext and Local Database

    To understand more on this refer http://msdn.microsoft.com/en-us/library/hh202860(VS.92).aspx

    So what you need is the good old tie up between Silverlight and LINQ to SQL. Here we go.

    You need to refer System.Data.Linq assembly and use the below two namespaces to define the model.

    using System.Data.Linq;
    using System.Data.Linq.Mapping;
    

    After that you need to define the model by hand.

    //Model Class
    [Table]
    public class EmailClass
    {
        [Column(IsDbGenerated = true, IsPrimaryKey = true)]
        public int Id { get; set; }
        [Column()]
        public string EmailAddress { get; set; }
    }
    

    Once the model is defined you then need the DataContext

    public class EmailContext : DataContext
    {
        public EmailContext(string sConnectionString)
            : base(sConnectionString)
        { }
    
        public Table<EmailClass> Emails
        {
            get
            {
                return this.GetTable<EmailClass>();
            }
        }
    }
    

    Connection string would look like,

    string ConnectionString = "Data Source=isostore:/EmailDB.sdf";
    

    Some reusable methods to Add and Display

    public IList<EmailClass> GetEmails()
    {
        List<EmailClass> emails = new List<EmailClass>();
        using (var db = new EmailContext(ConnectionString))
        {
            var query = from e in db.Emails
                        select e;
            emails = query.ToList();
        }
    
        return emails;
    }
    
    public void AddEmail(EmailClass _email)
    {
        using (var db = new EmailContext(ConnectionString))
        {
            db.Emails.InsertOnSubmit(_email);
            db.SubmitChanges();
        }
    }
    

    Then comes UI which would help you to save and display data,

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Orientation="Horizontal">
            <TextBox Width="300" x:Name="txtEmail"></TextBox>
            <Button HorizontalAlignment="Right" x:Name="btnSave" Content="Save" Width="120" Click="btnSave_Click"></Button>
        </StackPanel>
        <ListBox x:Name="lstEmails" Grid.Row="1" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Path=EmailAddress}"></TextBlock>
                        <TextBlock Text="-----"></TextBlock>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>            
    </Grid>
    

    The complete code is as below,

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using System.Data.Linq;
    using System.Data.Linq.Mapping;
    
    namespace WP7_Samples
    {    
        public partial class LocalDB_WP7 : PhoneApplicationPage
        {
            const string ConnectionString = "Data Source=isostore:/EmailDB.sdf";
            public LocalDB_WP7()
            {
                InitializeComponent();
    
                InputScope _scope = new InputScope();
                InputScopeName _scopeName = new InputScopeName();
                _scopeName.NameValue = InputScopeNameValue.EmailNameOrAddress;
                _scope.Names.Add(_scopeName);
    
                txtEmail.InputScope = _scope;
    
                using (var db = new EmailContext(ConnectionString))
                {
                    if (!db.DatabaseExists())
                        db.CreateDatabase();
    
                    LoadData();
                }
            }
    
            public void LoadData()
            {
                lstEmails.ItemsSource = GetEmails();
            }
    
            public IList<EmailClass> GetEmails()
            {
                List<EmailClass> emails = new List<EmailClass>();
                using (var db = new EmailContext(ConnectionString))
                {
                    var query = from e in db.Emails
                                select e;
                    emails = query.ToList();
                }
    
                return emails;
            }
    
            public void AddEmail(EmailClass _email)
            {
                using (var db = new EmailContext(ConnectionString))
                {
                    db.Emails.InsertOnSubmit(_email);
                    db.SubmitChanges();
                }
            }
    
            private void btnSave_Click(object sender, RoutedEventArgs e)
            {
                if (txtEmail.Text.Trim() != "")
                {
                    var emailObj = new EmailClass() { EmailAddress = txtEmail.Text.Trim() };
                    AddEmail(emailObj);
                }
                LoadData();
                txtEmail.Text = "";
            }
        }
    
        //Model Class
        [Table]
        public class EmailClass
        {
            [Column(IsDbGenerated = true, IsPrimaryKey = true)]
            public int Id { get; set; }
            [Column()]
            public string EmailAddress { get; set; }
        }
    
        public class EmailContext : DataContext
        {
            public EmailContext(string sConnectionString)
                : base(sConnectionString)
            { }
    
            public Table<EmailClass> Emails
            {
                get
                {
                    return this.GetTable<EmailClass>();
                }
            }
        }
    }
    

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : How to change Startup Page

    • 1 Comments

    Windows Phone 7 Silverlight project generally starts by opening MainPage.xaml. How to change this?

    Under solution explorer, expand Properties and open WMAppManifest.xml and there we can change it

    <Tasks>
      <DefaultTask Name="_default" NavigationPage="LocalDB_WP7.xaml" />
    </Tasks>
    

    Namoskar!!!!

  • Wriju's BLOG

    Windows Phone 7 : IsolatedStorage Save and Read Data to a File

    • 4 Comments

    Windows Phone 7 apps runs in an isolated environment and often application needs store and retrieve data from files. Application can use its IsolatedStorage to store and retrieve data.

    The example shows how to read from a  file and display it in ListBox and save data to the file located in its isolated storage.

    We need the class to create a structure for UI data binding.

    //Creating the structure to display
    public class MyDataClass
    {
        public string MSG { get; set; }
    }
    

    After that define the UI look,

    <ListBox Background="White" x:Name="lstDisplay" Grid.Row="1" >
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock FontSize="20" Foreground="Black" Text="{Binding Path=MSG}"></TextBlock>
                    <TextBlock Foreground="Black" Text="---"></TextBlock>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>                
    </ListBox>
    

    We now need to initialize the IsolatedStorage for our application.

    IsolatedStorageFile myFile = IsolatedStorageFile.GetUserStoreForApplication();
    string sFile = "DataTest.txt";
    

    Once done we will start reading lines form the inline text file.

    public void LoadData()
    {
        //myFile.DeleteFile(sFile);
        if (!myFile.FileExists(sFile))
        {
            IsolatedStorageFileStream dataFile = myFile.CreateFile(sFile);
            dataFile.Close();
        }
    
        //Reading and loading data
        StreamReader reader = new StreamReader(new IsolatedStorageFileStream(sFile, FileMode.Open, myFile));
        string rawData = reader.ReadToEnd();
        reader.Close();
    
        string[] sep = new string[] { "\r\n" }; //Splittng it with new line
        string[] arrData = rawData.Split(sep,StringSplitOptions.RemoveEmptyEntries);
                            
        List<MyDataClass> dataList = new List<MyDataClass>();
        foreach (var d in arrData)
        {
            dataList.Add(new MyDataClass() { MSG = d });
        }
        //Binding data to the UI for display
        lstDisplay.ItemsSource = dataList;
    }
    

    Below is how we can save the data in the file.

    private void btnSave_Click(object sender, RoutedEventArgs e)
    {
        if (txtMSG.Text.Trim() !="")
        {
            string sMSG = txtMSG.Text;
            StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream(sFile, FileMode.Append, myFile));
            sw.WriteLine(sMSG); //Wrting to the file
            sw.Close();
    
            //Refresh the display
            LoadData();
            txtMSG.Text = "";
        }
    }
    

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : How to play media

    • 0 Comments

    Windows Phone 7 can flawlessly play media files. There are list of supported codec which Windows Phone 7 can play. However below is the simple XAML which can enable the media loading.

    <MediaElement x:Name="myVideo" AutoPlay="True" Source="Kalimba.mp3" />

    You can also control various behaviors through your code. 

    Note.

    1. Now while using the Windows Phone 7 Emulator you will not be able to play video file. But the audio file is easy to play as mentioned above.

    2. Also you need to ensure if you are using local media file the Build Type of that media should be Content

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : Reading Twitter Timeline

    • 2 Comments

    This one is similar to my previous post on Reading RSS. But useful in Phone App.

    So you need the structure as below

    public class TWClass
    {
        public string TextMSG { get; set; }
        public string CreatedDt { get; set; }
    }
    

    After that you need the below code to get your Twitter timeline. My Twitter handle is wriju_ghosh. I have hardcoded it. You can make it dynamic as well.

    public Page1()
    {
        InitializeComponent();
            
        WebClient myTweet = new WebClient();
        myTweet.DownloadStringCompleted += new DownloadStringCompletedEventHandler(myTweet_DownloadStringCompleted);
    
        myTweet.DownloadStringAsync(new Uri(@"http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=wriju_ghosh"));
    }
    
    void myTweet_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        //Need to check Network/WiFi etc before proceeding further..
        var TWData = from tw in XElement.Parse(e.Result).Descendants("status")
                        select new TWClass
                        {
                            TextMSG = tw.Element("text").Value,
                            CreatedDt = tw.Element("created_at").Value
                        };
        lstTW.ItemsSource = TWData;    
    }
    

    Now UI would look like (this can be better).

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <ListBox Name="lstTW" Margin="0,0,6,0">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Width="400">
                        <TextBlock Text="{Binding Path=TextMSG}"></TextBlock>
                        <TextBlock Text="{Binding Path=CreatedDt}"></TextBlock>
                        <TextBlock Text="----"></TextBlock>
                    </StackPanel>                    
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>            
    </Grid>
    

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : Checking Network Connections before Downloading

    • 0 Comments

    Not every user will use unlimited data connections. So as a good application developer you should check and notify user whether they would like to proceed further or not.

    Some of the quick things you may want to do

    //Check if network is available
    var _isNetworkAvailable = Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.IsNetworkAvailable;
    
    //Check if Cell Data connection is available
    var _isCellDataAvailable = Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.IsCellularDataEnabled;
    
    //Check if the cell data connection is in ROaming
    var _isCellDataRoaming = Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.IsCellularDataRoamingEnabled;
    
    //Check if WiFi Network is available
    var _isWiFiEnabled = Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.IsWiFiEnabled;
    
    

    You can also check who is the mobile provider, a quick one to let user know if they are in Roaming and not using their parent connection

    Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.CellularMobileOperator;
    

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : Building Simple RSS Reader

    • 5 Comments

    Here we will build simple RSS reader in Windows Phone. Reading RSS is reading XML file online. So you need some engineering between XML and XAML. Here you go.

    Your phone UI

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <ListBox Name="lstRSS">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Path=Title}"></TextBlock>
                        <TextBlock Text="{Binding Path=PubDate}"></TextBlock>
                        <TextBlock Text=" "></TextBlock>
                    </StackPanel>                    
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>            
    </Grid>
    

    Then the class to define the structure

    public class RSSClass
    {
        public string Title { get; set; }
        public string PubDate { get; set; }
    }
    

    After that we need few lines to read it online.

    public Page1()
    {
        InitializeComponent();
    
        WebClient myRSS = new WebClient();
        myRSS.DownloadStringCompleted += new DownloadStringCompletedEventHandler(myRSS_DownloadStringCompleted);
    
        //Read Async
        myRSS.DownloadStringAsync(new Uri(@"http://blogs.msdn.com/b/wriju/rss.aspx"));
    }
    
    void myRSS_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        //Check if the Network is available
        if (!Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.IsNetworkAvailable)
        {
            var rssData = from rss in XElement.Parse(e.Result).Descendants("item")
                            select new RSSClass
                            {
                                Title = rss.Element("title").Value,
                                PubDate = rss.Element("pubDate").Value
                            };
            lstRSS.ItemsSource = rssData;
        }
        else
        {
            MessageBox.Show("No network is available..");
        }
    }
    

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : Handling Hardware Back Button

    • 1 Comments

    Often user presses hardware back button while inside an application. This would send the existing application to the background and let other be on top. Most of the times this is acceptable but sometimes application requires user to choose whether to go back or notify about it. Handling back button through code,

    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
    {
        e.Cancel = true; //Cancelling the default back option
        MessageBox.Show("You have pressed hardware back button");            
    }
    

    Namosakr!!!

  • Wriju's BLOG

    Windows Phone 7 - Binding Data to ListBox through Code

    • 9 Comments

    In Windows Phone 7 we need to display data programmatically. Below one demonstrates the simply way of binding data through code.

    Suppose you have Emp class as below.

    public class Emp
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
    

    Let’s create List<Emp>

    List<Emp> myData = new List<Emp>()
    {
        new Emp(){Id = 1, Name = "Wriju"},
        new Emp(){Id = 2, Name = "Writam"},
        new Emp(){Id = 3, Name = "Saswati"},
        new Emp(){Id = 4, Name = "Wrishika"},
        new Emp(){Id = 5, Name = "Baba"},
        new Emp(){Id = 6, Name = "Ma"}
    };
    

    After that format the ListBox to display it properly.

    <Grid>
        <ListBox Name="listBoxEmployee">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=Id}"></TextBlock>
                        <TextBlock Text=" - "></TextBlock>
                        <TextBlock Text="{Binding Path=Name}"></TextBlock>
                    </StackPanel>
                </DataTemplate>               
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
    

    Now, you need to simply code to bind the data

    lstData.ItemsSource = myData;
    

    This is a very simple example but useful in many scenario and applied to most of the data-bound application.

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : How to Vibrate Phone

    • 0 Comments

    Below is how you can vibrate the phone programmatically. Duration should be positive or less than 5.

    image

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : How to get Phone and Application memory information

    • 0 Comments

    If you want to get the memory information of your phone and application

    //Total Phone Memory (in bytes)
    var totalMemory = Microsoft.Phone.Info.DeviceStatus.DeviceTotalMemory;
    textBlock1.Text += Environment.NewLine + (totalMemory/(1024 * 1024)).ToString();
    
    //Application Current Memory Usage (bytes)
    var appCurrentMemoryUsage = Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage;
    textBlock1.Text += Environment.NewLine + appCurrentMemoryUsage.ToString();
    
     

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : How to get the manufacturer name

    • 0 Comments

    Below is how you can get the device manufacturer name.

    //Device Manufacturer
    var manufacturer = Microsoft.Phone.Info.DeviceStatus.DeviceManufacturer;
    textBlock1.Text += Environment.NewLine + manufacturer.ToString();
    

    Namoskar!!!

  • Wriju's BLOG

    Windows Phone 7 : How to get the device name

    • 0 Comments

    Below is how you can retrieve the phone name.

    //Phone Name
    var PhoneName = Microsoft.Phone.Info.DeviceStatus.DeviceName;
    textBlock1.Text += Environment.NewLine + PhoneName.ToString();
    

    Namoskar!!!

Page 7 of 25 (606 items) «56789»