I am trying to develop a pivot application for Windows Phone 7 using Visual Studio 2010. I got the data from the calendar with the following code.
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)
{
//No results
}
}
The problem comes when I tried to connect to the next button.
private void button2_Click(object sender, RoutedEventArgs e)
{
if (AppointmentResultsDataLINQ.DataContext.ToString() == "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();
How can I convert the data to string so that it can play the two songs correctly? Because right now, even though I set the event to "Meeting" on the calendar, it still plays the second song.
You have binded the ListBox using the Appointment object, so the DataContext needs to be typecasted into the same. And by setting the event as Meeting if it means setting the Subject field of Appointment class as "Meeting" then this code should work fine.
if ((((Appointment)(AppointmentResultsDataLINQ.DataContext)).Subject).Equals("Meeting")))
{
mediaElement1.Source = new Uri("http://www.opendrive.com/files/NV8zNTMwNDYwX2hxRXZR/Crystallize.mp3", UriKind.Absolute);
}
When you are doing AppointmentResultsDataLINQ.DataContext.ToString() you are converting the DataContext object's address value to string and not getting the required string value. Also "==" doesn't work for string comparisons.
Related
So, as the subject says...what is the easiest way to hide FormRegion if email is in Reply mode whether its in a new window or with InlineResponse?
Just set the FormRegion.Visible property which returns a Boolean value that indicates whether the form region is visible or hidden.
Went back to test the approach in my answer after the question from #EugeneAstafiev and -- of course -- this was more complicated than I first thought... but I did get it working with some additional code.
The issue is that when the user clicks "Reply", it opens a new inspector window with a new instance of the FormRegion. So setting the Visible property to false in the event handler sets it only on the current "Read" mode inspector window -- rather than the new "Compose" mode inspector window that gets opened. So, instead the code samples below set up a bool flag property in ThisAddIn called LoadFormRegion that can be toggled to "false" when the Reply or ReplyAll event is fired.
Also, I noticed that setting Visible to false on the FormRegion still draws the area of the FormRegion on the inspector window, just with nothing in it. To completely prevent the FormRegion from loading, you can test for "Compose" mode and then the ThisAddin.LoadFormRegion flag in the FormRegionInitializing event handler located inside of the "Form Region Factory" at the top of the code page -- which is usually folded away from view. In that code block, setting "e.Cancel = true" will prevent the FormRegion from loading at all.
Here is the revised code for the FormRegion, which now subscribes to all three email button click events (Reply, ReplyAll, Forward), and sets the ThisAddIn.LoadFormRegion flag accordingly:
namespace TESTINGOutlookAddInVSTO
{
partial class FormRegion1
{
#region Form Region Factory
[Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Note)]
[Microsoft.Office.Tools.Outlook.FormRegionName("TESTINGOutlookAddInVSTO.FormRegion1")]
public partial class FormRegion1Factory
{
// Occurs before the form region is initialized.
// To prevent the form region from appearing, set e.Cancel to true.
// Use e.OutlookItem to get a reference to the current Outlook item.
private void FormRegion1Factory_FormRegionInitializing(object sender, Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
{
if (e.FormRegionMode == Outlook.OlFormRegionMode.olFormRegionCompose)
{
var myAddIn = Globals.ThisAddIn;
if (myAddIn.LoadFormRegion == false)
{
e.Cancel = true;
}
}
}
}
#endregion
// Occurs before the form region is displayed.
// Use this.OutlookItem to get a reference to the current Outlook item.
// Use this.OutlookFormRegion to get a reference to the form region.
private void FormRegion1_FormRegionShowing(object sender, System.EventArgs e)
{
// Reset ThisAddIn.LoadFormRegion flag to true (in case user starts
// composing email from scratch without clicking Reply, ReplyAll or Forward)
var myAddin = Globals.ThisAddIn;
myAddin.LoadFormRegion = true;
var myMailItem = this.OutlookItem as Outlook.MailItem;
// Track these events to set the ThisAddIn.FormRegionShowing flag
((Outlook.ItemEvents_10_Event)myMailItem).Reply += myMailItem_Reply;
((Outlook.ItemEvents_10_Event)myMailItem).ReplyAll += myMailItem_ReplyAll;
((Outlook.ItemEvents_10_Event)myMailItem).Forward += myMailItem_Forward;
}
// Sets FormRegionShowing flag on ThisAddin
private void SetFormRegionShowing(bool show)
{
var myAddIn = Globals.ThisAddIn;
myAddIn.LoadFormRegion = show;
}
private void myMailItem_Forward(object Forward, ref bool Cancel)
{
SetFormRegionShowing(true);
}
private void myMailItem_ReplyAll(object Response, ref bool Cancel)
{
SetFormRegionShowing(false);
}
private void myMailItem_Reply(object Response, ref bool Cancel)
{
SetFormRegionShowing(false);
}
// Occurs when the form region is closed.
// Use this.OutlookItem to get a reference to the current Outlook item.
// Use this.OutlookFormRegion to get a reference to the form region.
private void FormRegion1_FormRegionClosed(object sender, System.EventArgs e)
{
}
}
}
And here's the new code for ThisAddIn to setup the LoadFormRegion property flag:
namespace TESTINGOutlookAddInVSTO
{
public partial class ThisAddIn
{
private bool loadFormRegion;
public bool LoadFormRegion { get => loadFormRegion; set => loadFormRegion = value; }
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
LoadFormRegion = true;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Note: Outlook no longer raises this event. If you have code that
// must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
Tested the above and works nearly perfectly... I noticed that if there is a "Draft" reply in the user's Inbox created before the add-in was loaded, clicking on that email to continue editing in the Preview window or a new inspector window will cause some wonky display issues with the FormRegion. However, once I closed out that draft, then everything seemed to return to normal.
all. I am trying to develop an application for Windows Phone 7 using Visual Studio 2010. It is a music player that is supposed to be able to play music based on the current event.
I managed to extract the event but when I tried to combine it with the player, the entire player would just crash. Here are the codes.
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)
{
//No results
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
if ((((Appointment)(AppointmentResultsDataLINQ.DataContext)).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();
}
The problem is the cast. You are trying to cast the AppointmentResultsDataLINQ.DataContext to an Appointment. This does not make sense. You need to select one concrete appointment from using LINQ (similar to the code in your Appointments_SearchCompleted that imho does nothing)
The app is like a small dictionary. I have a listbox and a textbox. The list box is already filled with words and when there is any entry in the textbox the listbox is refilled again with words starting with the letters in the textbox. I have a listbox SelectionChanged event implemented when the user clicks on a word its meaning appears. The problem is when user selects a word from the list and then types something in the textbox, listBox SelectionChanged event is called i dont want this to happen because at this point of time my listbox's selected item is empty.I would like to have a event that is fired only when user selects something from the listbox. It should not be fired when the content of the listbox changes. Thank you
You can use
1.if (lstWords.SelectedItem != null)
2.lstWords.SelectedIndex = -1;
for e.g. following is the source code for text changed event and list selection change event
private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (textBox1.Text.ToString().Equals(""))
{
XmlDictionaryRepository test = new XmlDictionaryRepository();
lstWords.ItemsSource = test.GetWordList(categorySelected,xmlFileName);
}
else
{
XmlDictionaryRepository test = new XmlDictionaryRepository();
lstWords.ItemsSource = test.GetMatchWordList(categorySelected, textBox1.Text.ToString(),xmlFileName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), (((PhoneApplicationFrame)Application.Current.RootVisual).Content).ToString(), MessageBoxButton.OK);
}
}
private void lstWords_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
if (lstWords.SelectedItem != null)
{
string wordSelected = ((Glossy_Test.Dictionary)(lstWords.SelectedItem)).Word;
if (lstWords.SelectedItem != null)
{
NavigationService.Navigate(new Uri(string.Format("/DescribeWord.xaml?param1={0}¶m2={1}", wordSelected, categorySelected), UriKind.Relative));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), (((PhoneApplicationFrame)Application.Current.RootVisual).Content).ToString(), MessageBoxButton.OK);
}
finally
{
// lstWords.SelectedIndex = -1;
}
}
I am trying to controll the snooze and dismiss button when the alarm sound in windows phone 7.
But i couldnt find any source code example on it.
Can anyone help me with it?
What i want is like when i clicked on the snooze or dimiss button it will do something such as the dismiss button will naviagte to another page.
And one more thing is that when the alarm is triggered can i set it to play some music??
Because the one that i have tried out does not play any music.
private static void CreateAlarm(string title, string time)
{
var alarm = new Alarm(title)
{
Content = "You have a meeting with your team now.",
BeginTime = Convert.ToDateTime(time),
};
ScheduledActionService.Add(alarm);
}
private static void ResetAlarm()
{
ScheduledActionService.Remove("MyAlarm");
}
private void SetAlarm_Click(object sender, RoutedEventArgs e)
{
string time = Convert.ToString(timePicker1.ValueString);
CreateAlarm(txtTitle.Text, time);
}
private void ResetAlarm_Click(object sender, RoutedEventArgs e)
{
ResetAlarm();
}
}
The Alarm class has a .Sound property to controls the sound file that is played.
To use it, say you have Alarm.mp3 in your project under the Sounds folder with it's build action set to Content.
var alarm = new Alarm() {
Sound = new Uri('Sounds/Alarm.mp3', UriKind.Relative)
}
There is no way to respond to snooze or dismiss that I have seen.
hey guys, i have a usercontrol within the default email compose form, I want to get the mailitem of that window.
Is there an easy way to do this?
Since you are composing an email, you must be in an Outlook Inspector. So you would have code like this:
Inspector inspector = window as Inspector;
MailItem mailItem = inspector.CurrentItem as MailItem;
Assuming you have some type of CheckBox or RadioButton control on your user UserControl you could utilize the ActiveInspector to get a hold of the mailItem:
using Outlook = Microsoft.Office.Interop.Outlook;
namespace My_Outlook_Plugin
{
public partial class UserControl_Classification : UserControl
{
public UserControl_Classification()
{
InitializeComponent();
}
private void UserControl_Classification_Load(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
try
{
Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
if (inspector.CurrentItem is Outlook.MailItem)
{
MailItem mailItem = inspector.CurrentItem as MailItem;
//Do something with mailItem
Marshal.ReleaseComObject(mailItem);
}
}
catch (System.Exception ex)
{ }
}
}
Also, this is a really good explanation on setting up a wrapper which you need to to to track each potential mailItem window the the user might open and dispose of it properly - enter link description here