locked
Right tapped visual feedback rectangle

    Question

  • Hi,

    i need my control to show the rectangle when long pressed (right tapped). Before Win 8 RTM every Control showed this rectangle. What do i need to implement to make Windows show this rectangle? ( Like the TextBox is doing.)

    Monday, August 20, 2012 2:11 PM

Answers

  •  Hello,

    I believe these links should answer your question:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh465300.aspx

    http://code.msdn.microsoft.com/windowsapps/Context-menu-sample-40840351

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, August 22, 2012 10:18 PM
    Moderator
  • Hello,

    It appears that you must setup a GestureRecognizer to enable the "tap and hold" hint.

    Thank you very much for the clarification. Please add the following code just after your call to "InitializeComponent" to facilitate the functionality that you are expecting:

                _gr.GestureSettings |= GestureSettings.Hold;
                Window.Current.CoreWindow.PointerPressed += (s, e) =>
                {
                    _gr.ProcessDownEvent(e.CurrentPoint);
                };
                Window.Current.CoreWindow.PointerReleased += (s, e) =>
                {
                    _gr.ProcessUpEvent(e.CurrentPoint);
                };
                Window.Current.CoreWindow.PointerMoved += (s, e) =>
                {
                    _gr.ProcessMoveEvents(e.GetIntermediatePoints());
                };

    And add this at class level:

    GestureRecognizer _gr = new GestureRecognizer();

    I hope this helps,

    James 


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, August 30, 2012 11:45 PM
    Moderator

All replies

  • Hi,

    Not clear your point, do you have any image to show this effect?
    Or you can try to set IsRightTapEnabled="False"

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, August 21, 2012 9:31 AM
  • example:

    when you touch and hold in a textbox then you get a visual feedback in form of a rectangle. this rectangle was coming on all controls before windows 8 rtm.

    I need to show up this rectangle on my own control. how to do this?

    Tuesday, August 21, 2012 6:01 PM
  • Hello,

    Thanks for your feedback, I will involve more experts to investigate it.

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, August 22, 2012 12:15 PM
  •  Hello,

    I believe these links should answer your question:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh465300.aspx

    http://code.msdn.microsoft.com/windowsapps/Context-menu-sample-40840351

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, August 22, 2012 10:18 PM
    Moderator
  • Hi,

    look at this picture :

    When you "Press And Hold" on a TextBox you get this visual feedback in from of a rectangle. Then you know when you release your finger you get a context menu or you know you get a right tap event.

    Try this here in the first Scenario of the same sample:

    When you "Press And Hold" your finger on this Icon this rectangle is not showing up.

    Thursday, August 23, 2012 7:04 AM
  • Hello,

    Do you still need help with this or were the links on context menus I posted helpful?

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Friday, August 24, 2012 8:36 PM
    Moderator
  • Hi,

    i need still help. The links were no help for me.

    Monday, August 27, 2012 6:28 AM
  • Hello,

    Why were the links not helpful? I apologize but I guess I am still a bit confused about what you are asking. Are you saying that there is a differnce between right click and tap and hold? The copy / paste context menu is specific to the text box. I don't understand why you think every control should have this feature. You should be able to implement this feature using a custom context menu. Plesae let me know what I am missing.

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, August 28, 2012 9:39 PM
    Moderator
  • I believe he's asking how to get the visual feedback for press-and-hold (the translucent square that pops up, showing that you've held long enough). In the C++ version of the sample, you don't get that feedback when press-and-holding the Word icon - there's no indication that you've held your press long enough for the context menu to appear when you release.

    In the JavaScript sample, the feedback square appeared correctly; it seems as though it's automatically applied as soon as I add a "contextmenu" event handler. The C# sample fails though, just like C++.

    James, if you're still confused, shoot me an email - my alias is rnichols. I'm afraid I don't know enough about XAML to determine the root issue.

    Wednesday, August 29, 2012 6:36 AM
  • Ross Nichols has understood what i mean. I need this square to Show up.
    Thursday, August 30, 2012 6:19 AM
  • Hello,

    It appears that you must setup a GestureRecognizer to enable the "tap and hold" hint.

    Thank you very much for the clarification. Please add the following code just after your call to "InitializeComponent" to facilitate the functionality that you are expecting:

                _gr.GestureSettings |= GestureSettings.Hold;
                Window.Current.CoreWindow.PointerPressed += (s, e) =>
                {
                    _gr.ProcessDownEvent(e.CurrentPoint);
                };
                Window.Current.CoreWindow.PointerReleased += (s, e) =>
                {
                    _gr.ProcessUpEvent(e.CurrentPoint);
                };
                Window.Current.CoreWindow.PointerMoved += (s, e) =>
                {
                    _gr.ProcessMoveEvents(e.GetIntermediatePoints());
                };

    And add this at class level:

    GestureRecognizer _gr = new GestureRecognizer();

    I hope this helps,

    James 


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, August 30, 2012 11:45 PM
    Moderator
  • Hi,

    i have still a problem with this solution.

    I have written a minimal Project showing this Problem.

    Do this:

    1) Start the sample app.

    2) Open the onscreen touch Keyboard manually.

    3) Use your finder(in Simulator "touch mode") and pan the page a bit.

    4) Now touch anywhere on the page.

    You get an exception saying: ..." Failed to start tracking the pointer, because it is already being tracked. " ...

    How to fix this?

    I am not able to upload this sample here so here the essential code ( the Project is based on the blank template):

    MainPage.xml:

    <Page
        x:Class="App1.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App1"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid >
            <Image Source="Assets/fl.jpg"/>
            </Grid>
    
    </Page>
    

    MainPage.xaml.h:

    //
    // MainPage.xaml.h
    // Declaration of the MainPage class.
    //
    
    #pragma once
    
    #include "MainPage.g.h"
    
    namespace App1
    {
    	/// <summary>
    	/// An empty page that can be used on its own or navigated to within a Frame.
    	/// </summary>
    	public ref class MainPage sealed
    	{
    	public:
    		MainPage();
    
    	protected:
    		virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
    	private:
    		Windows::UI::Input::GestureRecognizer^ m_gestureRecognizer;
    		Windows::Foundation::EventRegistrationToken m_coreWindowPointerPressedToken;
    		Windows::Foundation::EventRegistrationToken m_coreWindowPointerReleasedToken;
    		Windows::Foundation::EventRegistrationToken m_coreWindowPointerMovedToken;
    
    		void CoreWindowPointerPressed( Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    		void CoreWindowPointerReleased( Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    		void CoreWindowPointerMoved( Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
    	};
    }

    MainPage.xaml.cpp:

    //
    // MainPage.xaml.cpp
    // Implementation of the MainPage class.
    //
    
    #include "pch.h"
    #include "MainPage.xaml.h"
    
    using namespace App1;
    
    using namespace Platform;
    using namespace Windows::Foundation;
    using namespace Windows::Foundation::Collections;
    using namespace Windows::UI::Xaml;
    using namespace Windows::UI::Xaml::Controls;
    using namespace Windows::UI::Xaml::Controls::Primitives;
    using namespace Windows::UI::Xaml::Data;
    using namespace Windows::UI::Xaml::Input;
    using namespace Windows::UI::Xaml::Media;
    using namespace Windows::UI::Xaml::Navigation;
    
    using namespace Windows::UI::Core;
    using namespace Windows::UI::Input;
    // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
    
    MainPage::MainPage()
    {
    	m_gestureRecognizer = ref new GestureRecognizer();
    	InitializeComponent();
    	m_gestureRecognizer->GestureSettings |= GestureSettings::Hold;
    
    	m_coreWindowPointerPressedToken		= Window::Current->CoreWindow->PointerPressed += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &MainPage::CoreWindowPointerPressed);
    	m_coreWindowPointerReleasedToken	= Window::Current->CoreWindow->PointerReleased += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &MainPage::CoreWindowPointerReleased);
    	m_coreWindowPointerMovedToken		= Window::Current->CoreWindow->PointerMoved += ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &MainPage::CoreWindowPointerMoved);
    	
    }
    
    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.  The Parameter
    /// property is typically used to configure the page.</param>
    void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
    {
    	(void) e;	// Unused parameter
    }
    
    void MainPage::CoreWindowPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
    {
    	m_gestureRecognizer->ProcessDownEvent( args->CurrentPoint );
    }
    
    void MainPage::CoreWindowPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
    {
    	m_gestureRecognizer->ProcessUpEvent( args->CurrentPoint );
    }
    
    void MainPage::CoreWindowPointerMoved(CoreWindow^ sender, PointerEventArgs^ args) 
    {
    	m_gestureRecognizer->ProcessMoveEvents( args->GetIntermediatePoints() );
    }

     

    Monday, September 03, 2012 6:50 AM
  • Try this:

    http://sdrv.ms/QA6Gml

    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, September 11, 2012 12:27 AM
    Moderator
  • This answer is missing one crucial little bit -- if you're inside a ScrollViewer, you'll get a PointerCaptureLost if you move while in a hold. If you don't call GestureRecognizer.CompleteGesture(), you'll lose the rectangle until you reboot the app. Try this implementation:

    gr.GestureSettings |= GestureSettings.Hold;
    Window.Current.CoreWindow.PointerPressed += (s, e) =>
        {
            gr.ProcessDownEvent(e.CurrentPoint);
        };
    Window.Current.CoreWindow.PointerReleased += (s, e) =>
        {
            gr.ProcessUpEvent(e.CurrentPoint);
        };
    Window.Current.CoreWindow.PointerMoved += (s, e) =>
        {
            gr.ProcessMoveEvents(e.GetIntermediatePoints());
        };
    Window.Current.CoreWindow.PointerCaptureLost += (s, e) =>
        {
            gr.CompleteGesture();
        };
    Window.Current.CoreWindow.PointerExited += (s, e) =>
        {
            gr.CompleteGesture();
        };


    Wednesday, August 07, 2013 5:23 PM