how to get swipe in windows phone 7 - c#

I want to swipe images in windows phone 7.
Where do I begin from?

You can use the GestureService in the Silverlight Control Toolkit for Windows Phone 7. In your UI element, add the following piece of code (after you have referenced the toolkit's DLL in your WP7 project) -
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="OnFlick"/>
</toolkit:GestureService.GestureListener>
Implement the handler OnFlick in the code-behind file, like so -
private void OnFlick(object sender, FlickGestureEventArgs e)
{
var vm = DataContext as SelectedCatalogViewModel;
if (vm != null)
{
// User flicked towards left
if (e.HorizontalVelocity < 0)
{
// Load the next image
LoadNextPage(null);
}
// User flicked towards right
if (e.HorizontalVelocity > 0)
{
// Load the previous image
LoadPreviousPage();
}
}
}
Hope this helps,
indyfromoz

If you don't want to use the silverlight toolkit you can use the XNA framework.
http://www.nickharris.net/2010/11/using-touchpanel-for-gestures-in-windows-phone-7/

Try this:
using Microsoft.Phone.Controls;
public partial class MyControl
{
public MyControl()
{
InitializeComponent();
var gl = GestureService.GetGestureListener(asd);
gl.Flick += new EventHandler<FlickGestureEventArgs>(GestureListener_Flick);
}
private void GestureListener_Flick(object sender, FlickGestureEventArgs e)
{
if (e.Direction == Orientation.Horizontal)
{
if (e.HorizontalVelocity < 0) // determine direction (Right > 0)
{
//Some Action
}
else
{
//Some Action
}
}
}
}

Related

UWP app release version hangs on splash screen?

Debug versions (86, 64, ARM) all work fine, release versions build fine, but when they run all that happens is my app window opens and remains blank (white background). The only errors I see in the output are a whole bunch of:
...PDB file was not present when IL code was compiled to native.
I'm not sure if the missing .pdb files are the culprit - pretty sure they're not, cause they're just for debugging purposes right?
Anyways, this is the first UWP app I have tried to get ready for the Windows Store, and not completely sure if I have to do anything special like sign it to test release versions on my own computer?
Edit 1: Thank you #Alan for your suggestions, manually uninstalling the app sometimes gets me past the blank window to load the app bar, but then I am getting these errors when it doesn't hang on the splash screen:
Debugger Error 1,
Debugger Error 2
I have done nothing special to the splash screen, loaded all my visual assets using the built in tools in manifest, and have not modified App.xaml.cs from its default. Here is my Mainpage.cs:
using Sublist.Classes;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace Sublist
{
public sealed partial class MainPage : Page
{
const string TAG = "MainPage: ";
// for loading and saving user data and settings
public static DataHandler dataHandler;
public static MasterList<Entry> masterList;
//public static int listViewSelectedIndex = -1;
public MainPage()
{
this.InitializeComponent();
dataHandler = new DataHandler(this);
masterList = new MasterList<Entry>();
// load user data
if (dataHandler.userDataList != null)
masterList = dataHandler.userDataList;
masterList.UpdateListView(this);
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
dataHandler.LoadUserSettings();
}
private void AppBarAdd_Click(object sender, RoutedEventArgs e)
{
masterList.AddRow(this);
}
private void AppBarRemove_Click(object sender, RoutedEventArgs e)
{
if (!(mainListView.SelectedIndex < 0))
{
masterList.RemoveRow(this);
}
}
private void AppBarMoveDown_Click(object sender, RoutedEventArgs e)
{
}
private void AppBarMoveUp_Click(object sender, RoutedEventArgs e)
{
}
private void AppBarIndent_Click(object sender, RoutedEventArgs e)
{
// indent the row control if currently selected index is a list view item
if (-1 < mainListView.SelectedIndex && mainListView.SelectedIndex < mainListView.Items.Count)
{
// but don't allow more than one indent past above row's indent level
RowControl rc = (RowControl)mainListView.Items[mainListView.SelectedIndex];
int indexMinus1 = mainListView.SelectedIndex - 1;
if (-1 < indexMinus1 && rc.indentProp <= masterList[indexMinus1].indent)
{
rc.indentProp++;
}
}
// then update list view
masterList.UpdateListView(this);
}
private void AppBarUnindent_Click(object sender, RoutedEventArgs e)
{
// unindent the row control if currently selected index is a list view item
if (-1 < mainListView.SelectedIndex && mainListView.SelectedIndex < mainListView.Items.Count)
{
// but don't allow unindenting off left side of page
RowControl rc = (RowControl)mainListView.Items[mainListView.SelectedIndex];
if (rc.indentProp > 0)
{
rc.indentProp--;
}
}
// then update list view
masterList.UpdateListView(this);
}
public void AppBarShowCompl_Click(object sender, RoutedEventArgs e)
{
dataHandler.SaveUserSettings();
masterList.UpdateListView(this);
}
public void AppBarMarkAsCompleted_Click(object sender, RoutedEventArgs e)
{
// toggle hidden state of active entry
if (-1 < mainListView.SelectedIndex && mainListView.SelectedIndex < masterList.Count)
{
masterList[mainListView.SelectedIndex].completed = (masterList[mainListView.SelectedIndex].completed) ? false : true;
masterList.UpdateListView(this);
}
}
}
}
I have added the FileService and SettingsService classes from the opensource Template10 to the project.
The build setting "compile with .NET Native tool chain" was unchecked, I've tried deploying with it checked/unchecked for both debug/release versions, and now the debug version also often hangs on the splash screen? With it checked, I get a whole bunch of these errors as well:
'Sublist.exe' (Win32): Loaded 'C:\Windows\System32\biwinrt.dll'. Skipped loading symbols. Module is native, and native debugging is currently disabled.
I've tried downloading the server symbols with no success...
I found the hang happens at the following line in GetIfFileExitsAsync.
retval = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(key);
I made the following change in you code and it should work now.
In DataHandler's constructor, use Task.Run to initialize the userDataList.
public DataHandler(MainPage mp)
{
mainPage = mp;
settingsHelper = new SettingsHelper();
fileHelper = new FileHelper();
LoadUserSettings();
Task.Run(() =>
{
userDataList = LoadUserData();
});
Task.WaitAll();
}
I am still not sure why the .net native compile will make this issue, but will try to simplify the project and report it in MS internal channel.

Gyroscope and accelerometer data from Windows?

The Microsoft Surface Pro has a gyroscope and accelerometer, Windows 8, and the full .NET framework.
Most articles I find that talk about the motion API point to the Windows Phone 8 API.
What .NET Framework namespaces and classes should I be using to get gyroscope and accelerometer data from?
I just worked based off the documentation - http://msdn.microsoft.com/en-us/library/ie/windows.devices.sensors
using Windows.Devices.Sensors;
private Accelerometer _accelerometer;
private void DoStuffWithAccel()
{
_accelerometer = Accelerometer.GetDefault();
if (_accelerometer != null)
{
AccelerometerReading reading = _accelerometer.GetCurrentReading();
if (reading != null)
double xreading = reading.AccelerationX;
... etc.
}
}
Haven't tested it, but it should work for any Windows Store App - If you're trying to make it run as a console/windows forms app, you need to change the targetplatform by:
Right Click your project -> Unload Project
Follow the rest of this https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications
For the surface pro you need to use the Windows 8.1 library, instead of the Windows Phone 8.1 library.
It should be in the same Windows.Devices.Sensors namespace.
using Windows.Devices.Sensors;
...
//if you aren't already doing so, and you want the default sensor
private void Init()
{
_accelerometer = Accelerometer.GetDefault();
_gyrometer = Gyrometer.GetDefault();
}
...
private void DisplayAccelReading(object sender, object args)
{
AccelerometerReading reading = _accelerometer.GetCurrentReading();
if (reading == null)
return;
ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
}
...
private void DisplayGyroReading(object sender, object args)
{
GyrometerReading reading = _gyrometer.GetCurrentReading();
if (reading == null)
return;
ScenarioOutput_AngVelX.Text =
String.Format("{0,5:0.00}", reading.AngularVelocityX);
ScenarioOutput_AngVelY.Text =
String.Format("{0,5:0.00}", reading.AngularVelocityY);
ScenarioOutput_AngVelZ.Text =
String.Format("{0,5:0.00}", reading.AngularVelocityZ);
}

Making swipe work for a pivot control with embedded WebBrowser on Windows Phone 8.0

I'd like my application to have a Pivot control with a WebBrowser control in each PivotItem. The problem is that swiping to next PivotItem doesn't work since it instead results in scrolling the web page horizontally. However, the web pages are responsive and doesn't need to be scrolled horizontally so instead I want horizontal swiping to result in a pivot switch. Can this be accomplished? If I can't use a Pivot control what is the recommended way to implement page switching with WebControls on the pages? A top menu a la iOS/Android?
Yes it is possible, however needs little workaround since Webbrowser handles the event first and your Pivot probably doesn't know about it. You can use for this purpose Touch and its event FrameReported. Simple code can look like this:
public MainPage()
{
InitializeComponent();
Touch.FrameReported += Touch_FrameReported;
}
TouchPoint first;
private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
TouchPoint mainTouch = e.GetPrimaryTouchPoint(myWebBrowser);
if (mainTouch.Action == TouchAction.Down)
first = mainTouch;
else if (mainTouch.Action == TouchAction.Up)
{
if (mainTouch.Position.X - first.Position.X < 0)
MessageBox.Show("Next item.");
//myPivot.SelectedIndex++;
if (mainTouch.Position.X - first.Position.X > 0)
MessageBox.Show("Previous item.");
//myPivot.SelectedIndex--;
}
}
As you can see - I'm remembering the where the user start his movements, then when he releases his touch - I change myPivot.SelectetIndex. Hope this helps a little. You can also try with TouchPanel, but I think that will be simpler (if it's sufficient).
If you want to disable some gestures it can look for example like in the code below. I enabled only HorizontalDrag - so it won't fire for zoom. The tolerance of course shouldn't be 0, you will have to define the most suitable for your App.
// in MainPage() constructor
TouchPanel.EnabledGestures = GestureType.HorizontalDrag;
private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
TouchPoint mainTouch = e.GetPrimaryTouchPoint(myMap);
if (mainTouch.Action == TouchAction.Down)
first = mainTouch;
else if (mainTouch.Action == TouchAction.Up && TouchPanel.IsGestureAvailable)
{
if (mainTouch.Position.X - first.Position.X < 0)
MessageBox.Show("Next item.");
//myPivot.SelectedIndex++;
if (mainTouch.Position.X - first.Position.X > 0)
MessageBox.Show("Previous item.");
//myPivot.SelectedIndex--;
}
}
Here is the article that solves this particular issue http://blogs.msdn.com/b/madenwal/archive/2015/02/11/how-to-embed-a-webbrowser-control-inside-a-pivot-item-in-windows-phone.aspx

Kinect New Window Wpf

So I'm making a Kinect application using buttons, and to navigate the app, I'm making new windows for each button. I'm come across an issue I haven't been able to find any help at all on, and would appreciate any help.
So to open the new window, I'm using this:
private void button1_Click(object sender, RoutedEventArgs e)
{
//SUPPOSED to uninitialize the Kinect
UninitializeKinectSensor(this.Kinect;
//To open the new window
Window1 newwindow = new Window1();
newwindow.Show();
//To close the first window...
Close();
{
SO that one line is supposed to uninitialize the Kinect so it'll be free for the new window to use, but when it goes to the new window, the Kinect freezes. If I use the mouse to go back to the first window, it works on the first window again, which it shouldn't.
I also added in this line in the initialization phase
public Window1()
{
//Other init code is here, but this is the line I added. It doesn't seem to do anything.
InitializeKinectSensor(this.Kinect);
}
Any help is greatly appreciated!! I'm sure it's something simple and I just failed miserably haha XD
Do you really have to create a new window instead of using pages?
In your MainWindow you create a frame that takes all the window and use this frame to navigate between pages. This way, you'll keep the focus of the kinect in your whole application.
Depends alot on what UninitializeKinectSensor is actually doing. Just as a quick fix, though, you can try calling uninitialize on a background worker and see if that helps at all.
Instead of using the "Show()" use "ShowDialog()".It's better if you can create a static class or method to initialize and uninitialized kinect.
public static void start()
{
KinectSensor.KinectSensors.StatusChanged += kinectSensorsStatusChanged;
DiscoverSensor();
}
private static void kinectSensorsStatusChanged(object sender, StatusChangedEventArgs e)
{
KinectSensor oldSensor = Kinect;
if (oldSensor != null)
{
UninitializeKinect();
}
var status = e.Status;
if (Kinect == null)
{
//updateStatus(status);
if (e.Status == KinectStatus.Connected)
{
Kinect = e.Sensor;
DiscoverSensor();
}
}
else
{
if (Kinect == e.Sensor)
{
//updateStatus(status);
if (e.Status == KinectStatus.Disconnected ||
e.Status == KinectStatus.NotPowered)
{
Kinect = null;
sensorConflict = false;
DiscoverSensor();
}
}
}
}
private static DispatcherTimer readyTimer;
private static void UninitializeKinect()
{
if (speechRecognizer != null && Kinect != null)
{
Kinect.AudioSource.Stop();
Kinect.SkeletonFrameReady -= kinect_SkeletonFrameReady;
Kinect.SkeletonStream.Disable();
Kinect.Stop();
//this.FrameSkeletons = null;
speechRecognizer.RecognizeAsyncCancel();
speechRecognizer.RecognizeAsyncStop();
}
if (readyTimer != null)
{
readyTimer.Stop();
readyTimer = null;
}
}

windowless wpf application example?

Any advice or links or sample application (for VS2010) re how to develop a "windowless" WPF application?
That is the ones that look quite modern and don't seem to have the historical window chrome around the edges - they seem to have rounded edges etc...
I wrote a project that did exactly what you are talking about, we used the following project from Microsoft,
http://code.msdn.microsoft.com/WPFShell
Initially I tried writing it myself by turning off the chrome, not a good idea unless you don't want to be able to drag your window around in the standard windows method.
Just remove StartupUri and in the Application Startup method dont load a window:
public partial class App
{
public static bool IsTrue ;
public App()
{
Startup += AppStartup;
}
public void DoWork()
{
for (int i = 0; i < 10; i++)
{
Thread.Sleep(1000);
Trace.WriteLine("blah");
}
IsTrue = false;
}
void AppStartup(object sender, StartupEventArgs e)
{
IsTrue = true;
new Thread(DoWork).Start();
while (IsTrue)
{ }
Current.Shutdown();
}
}
}

Categories

Resources