How to determine orientation of Windows Phone 7? - windows-phone-7

How can you tell whether the device is oriented vertically (portrait) or horizontally (landscape)?
Is there an API that simplifies this or do you have to make the determination "by hand" using the accelerometer?

I myself just have looked at windows 7 phones(through vs2010 express phone edition).
It seems to have in the code behind this
public MainPage()
{
InitializeComponent();
// seems to set the supported orientations that your program will support.
SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
}
Then the actual form has
private void PhoneApplicationPage_OrientationChanging(object sender, OrientationChangedEventArgs e)
{
var test = e.Orientation;
}
So when the orientation changes it e.Orientation will tell you what orientation it is. Like for instance LandscapeRight.

Also you don't have to track this only via the event, you can ask for it directly from the PhoneApplicationPage instance:
private void Button_Click(object sender, RoutedEventArgs e)
{
MyCurrentOrientation.Text = this.Orientation.ToString();
}

You can also ask it through this.Orientation when your application starts so you know what the orientation is. Afther the start you can use the OrientationChanged event.
In your main:
OrientationChanged += new EventHandler<OrientationChangedEventArgs>(MainPage_OrientationChanged);
void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
Console.WriteLine(e.Orientation.ToString());
}

Related

How to change uwp app title bar color when Windows 10 change from dark theme to light and vice versa?

I have an app for test, with 3 buttons:
one for change title bar color to white
one for change title bar color to black
one for let the app title bar free to follow the Windows 10 theme color for its app title bar
Those first two buttons are ok and working, but the last one I don't know how to implement and where to put methods if necessary. I'd like, please, any help, tip or even a whole solution for the problem. Thank you in advance.
PS: would be great if title bar color can follow dark, light and even high contrast colors.
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace App7
{
public sealed partial class MainPage : Page
{
Windows.UI.ViewManagement.ApplicationViewTitleBar titleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;
public MainPage()
{
this.InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
titleBar.BackgroundColor = Windows.UI.Colors.White;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
titleBar.BackgroundColor = Windows.UI.Colors.Black;
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
//Title bar must be free to change its own colour accord/when/same time Windows theme change
//How can I do that?
//Where the code/methods goes?
}
}
}
You could handle the ColorValuesChanged Event of the UISettings Class. This event will happen when the Windows theme color is changed. You could get the current color of the Windows theme using UISettings.GetColorValue() to check if it is in Dark mode or Light mode. Then you could change the title bar color as you want.
Here is the code:
public Windows.UI.ViewManagement.UISettings uiSettings { get; set; }
private void Button_Click(object sender, RoutedEventArgs e)
{
uiSettings = new Windows.UI.ViewManagement.UISettings();
uiSettings.ColorValuesChanged += UiSettings_ColorValuesChanged;
// if you want to stop this.
//uiSettings.ColorValuesChanged -= UiSettings_ColorValuesChanged;
}
private void UiSettings_ColorValuesChanged(Windows.UI.ViewManagement.UISettings sender, object args)
{
// happens when the windows theme is changed.
// The color you get is either black(#FF000000) for dark theme or white(#FFFFFFFF) for light theme.
Color backgroundcolor = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.Background);
// change titlebar color.
Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar.BackgroundColor = backgroundcolor;
}

Lottie animationView isn't playing in XamarinForms after I change the source

When I try to change the source of an animationview to simulate play-stop solution, the source of the animationview is changed successfully, but when I click for the second time, it doesn't play the animation.
Here is my code:
private void AnimationView_OnClick(object sender, EventArgs e)
{
animationView.Play();
}
and on finish when I try to change the source:
private void AnimationView_OnFinish(object sender, EventArgs e)
{
if (animationView.Animation == "play_to_pause.json")
animationView.Animation = "pause_to_play.json";
else
animationView.Animation = "play_to_pause.json";
}
What am I doing wrong?
It will be your json files. I tried to recreate your issue and I had no problem.

Play loop of sound in WP7

i need to play a sound on the touch of screen, and it should remain in play state until user get his hands off from the screen. here is the code of mine,
private void OnMouseDown(object sender, Moenter code hereuseButtonEventArgs e)
{
clicked = true;
ColoringSound.Source = new Uri("Sounds/drawing.mp3", UriKind.Relative);
ColoringSound.Play();
}
private void OnMouseUp(object sender, MouseButtonEventArgs e)
{
clicked = false;
}
There is an MSDN article that describes how to loop MediaElements, all you have to do to stop a looped sound is invoke the Stop method.

Need help using the CameraCaptureTask

i am trying to create a simple demo application that does the following: i have a button at MainPage.xaml (with Name="btnCamera") and an image control (with Name="photo") and when i press the button i want to start the camera task, capture a photo and display it on the image control. The problem is that my code works on the emulator but not on a real device. The device i have is updated to the latest update(7740). Do you have an explanation for that or any change to my code to make it work? That is my code:
public partial class MainPage : PhoneApplicationPage
{
CameraCaptureTask _cameraCapture;
public MainPage()
{
InitializeComponent()
_cameraCapture = new CameraCaptureTask();
_cameraCapture.Completed += new EventHandler(_cameraCapture_Completed);
}
private void btnCamera_Click(object sender, RoutedEventArgs e)
{
try
{
_cameraCapture.Show();
}
catch (Exception)
{
MessageBox.Show("Error occured");
}
}
void _cameraCapture_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage image = new BitmapImage();
image.SetSource(e.ChosenPhoto);
photo.Source = image;
}
}
}
You need to make sure Zune is not running. The code looks fine and should work if you unplug the phone from the PC. If you want to debug whilst plugged into the PC, use WPConnect instead of Zune.

Alarm feature in Windows Phone 7

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.

Resources