2 Replies - 6276 Views - Last Post: 22 January 2013 - 09:23 AM

#1 cresschester  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-January 13

Getting a concrete event from Windows Phone 7 calendar

Posted 22 January 2013 - 03:49 AM

Hello.

I'm working on a WP7 application and I need it to play the song in the first link if the current event on the calendar is "Meeting". However, with the current code, the application just quit by itself the moment the player is started. May I know why?

Here is my code:

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 Microsoft.Phone.UserData;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
 
namespace PivotApp1
{
    public partial class MainPage : PhoneApplicationPage
    {  
        // Constructor
        public MainPage()
        {
            InitializeComponent();
 
            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
 
        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }
        }       
             
        private void button1_Click(object sender, RoutedEventArgs e)
        {           
            Appointments appts = new Appointments();
 
            //Identify the method that runs after the asynchronous search completes.
            appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);
 
            DateTime start = DateTime.Now;
            DateTime end = DateTime.Now;
            int max = 1;
                       
            //Start the asynchronous search.
            appts.SearchAsync(start, end, max, "Appointments Test #1");
            textBlock3.Text = DateTime.Now.ToString("hh:mm:ss tt");
        }
 
        void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
        {
            try
            {
                AppointmentResultsDataLINQ.DataContext =
                    from Appointment appt in e.Results
                    where appt.IsAllDayEvent == false                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                    select appt;             
 
          
            }
            catch (System.Exception)
            {
                
            }
        }
 
        private void button2_Click(object sender, RoutedEventArgs e)
        {
 
            if (((AppointmentResultsDataLINQ.DataContext as Appointment).Subject).Equals("Meeting"))
            {
                 mediaElement1.Source = new Uri("http://www.opendrive.com/files/NV8zNTMwNDYwX2hxRXZR/Crystallize.mp3", UriKind.Absolute);             
            }         
 
            else
            {
                mediaElement1.Source = new Uri("https://www.opendrive.com/files/NV8zMjAxODY0X0VBNDJY/Hetken%20tie%20on%20kevyt%20(piano%20cover)%20-%20YouTube.mp3", UriKind.Absolute);               
            }
                mediaElement1.Play();
        }         
    }
}


Is This A Good Question/Topic? 0
  • +

Replies To: Getting a concrete event from Windows Phone 7 calendar

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,159
  • Joined: 05-May 12

Re: Getting a concrete event from Windows Phone 7 calendar

Posted 22 January 2013 - 09:07 AM

Are you sure the URL is good for the case of a meeting? When it is not a meeting, do you get the same behavior?
Was This Post Helpful? 0
  • +
  • -

#3 cresschester  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-January 13

Re: Getting a concrete event from Windows Phone 7 calendar

Posted 22 January 2013 - 09:23 AM

View PostSkydiver, on 22 January 2013 - 09:07 AM, said:

Are you sure the URL is good for the case of a meeting? When it is not a meeting, do you get the same behavior?


I suspect something is wrong with the following line but I have no idea what it is.

if (((AppointmentResultsDataLINQ.DataContext as Appointment).Subject).Equals("Meeting"))


Also, here is the link to my full code.

http://www.mediafire...2lzk1nl20gu4bg9
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1