[Tips] Popup avec le Surface SDK 2.0
Grace au Surface SDK 2.0, on peut très simplement créer des applications touch sur n’importe quel PC tactile. Mon problème est que ce SDK ne propose pas de contrôle Popup et que l’utilisation de la Popup native WP4 pose des problèmes :
- Pas de gestion des évènements Touch
- Lorsqu’on touche l’écran on voit apparaitre le feedback par défaut de la tablette
Pour contourner ces deux problèmes vous pouvez utiliser cette classe (c’est un peu cracra mais ca marche) :
public class SurfacePopup : Popup
{
protected override void OnOpened(EventArgs e)
{
HwndSource hwndSource = PresentationSource.FromVisual((Visual)VisualTreeHelper.GetParent(Child)) as HwndSource;
// Enable surface input and touch events
hwndSource.EnableSurfaceInput();
// Disable visual tablet feedback
NativeMethods.EnableTabletGestures(hwndSource.Handle, false);
base.OnOpened(e);
}
public class NativeMethods
{
public static bool EnableTabletGestures(IntPtr hWnd, bool enable)
{
string atom = "MicrosoftTabletPenServiceProperty";
long num = (long)NativeMethods.GlobalAddAtom(atom);
if (num == 0L)
{
return false;
}
if (enable)
{
return NativeMethods.RemoveProp(hWnd, atom).ToInt64() == 1L;
}
int value = 16842777;
return NativeMethods.SetProp(hWnd, atom, new IntPtr(value)) == 1;
}
// Microsoft.Surface.Presentation.Common.NativeMethods
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern short GlobalAddAtom(string atom);
// Microsoft.Surface.Presentation.Common.NativeMethods
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr RemoveProp(IntPtr hWnd, string atom);
// Microsoft.Surface.Presentation.Common.NativeMethods
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int SetProp(IntPtr hWnd, string atom, IntPtr handle);
}
}
Ce post vous a plu ? Ajoutez le dans vos favoris pour ne pas perdre de temps à le retrouver le jour où vous en aurez besoin :