This is a migrated thread and some comments may be shown as answers.

Getting a concrete calendar event

3 Answers 51 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Maki
Top achievements
Rank 1
Maki asked on 22 Jan 2013, 08:26 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();
        }         
    }
}

3 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 22 Jan 2013, 11:06 AM
Hi Maki Maki,

Thank you for writing.

Since the application quits, most probably some type of exception is thrown. From the provided information we can't tell you for sure what causes it, so I'd like to ask you to prepare a sample project that reproduces the issue and send it to us. This way we will be able to debug it on our side and further investigate the cause for this issue if it is related to RadControls for Windows Phone.

Please note that you will need to open a new support ticket in order to be able to attach your solution.

All the best,
Todor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Maki
Top achievements
Rank 1
answered on 22 Jan 2013, 02:03 PM
Hello. Thank you for your reply. I don't exactly much time to recreate a sample project so I'm just going to attach the entire thing here. Is that okay?

http://www.mediafire.com/?2lzk1nl20gu4bg9

0
Todor
Telerik team
answered on 22 Jan 2013, 02:44 PM
Hi Maki,

First, the crush occurs here:
if (((AppointmentResultsDataLINQ.DataContext as Appointment).Subject).Equals("Meeting"))
This is because the LINQ query that sets the DataContext returns a collection and not a single appointment. This means that when you try to cast the collection to a single element, the result is null and trying to access the Subject property of an object that is null throws the exception which makes the app "quit by itself".

Second, I'd like to let you know that this forum is dedicated to RadControls for Windows Phone. It seems like you don't have a subscription for our suite and you don't use any of our components in the application that you are trying to create, neither. Please keep the communication to topics that are related to our controls.

Regards,
Todor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Calendar
Asked by
Maki
Top achievements
Rank 1
Answers by
Todor
Telerik team
Maki
Top achievements
Rank 1
Share this question
or