windows phone 8 - How to handle Tap event from Hold Event in WindowsPhone8? -
i have usercontrol , tap event in usercontrol itself..and having holding event usercontrol in phoneapplication page parent page.i want raise tap event hold event how achieve this?.. parentpage having:
<datatemplate x:key="template" > <chatbubble:chatbubblecontrol x:name="chatbubble" hold="chatbubblecontrol_hold_1" /> </datatemplate> usercontrol having..
<usercontrol.resources> .... <grid x:name="layoutroot" background="transparent" width="455" tap="chatbubble_tap" > ..... </grid> i want raise chatbubble_tap event chatbubblecontrol_hold_1
you can try raise event this:
// make eventhandler in parent page public , static available thru app public static void chatbubble_tap(object sender, system.windows.input.gestureeventargs e) { // code } // in usercontrol should able call this: private void chatbubblecontrol_hold_1(object sender, system.windows.input.gestureeventargs e) { yourpage.chatbubble_tap(sender, e); } this case depends on have in tap event (not can in static method).
you can pass handler of page usercontrol , invoke tap event handler (in case tap event can public (non-static). simple case can this:
// control in mainpage (or other page) <local:mycontrol x:name="yourcontrol" verticalalignment="center" grid.row="1"/> // initializing control , event invoked: public mainpage() { initializecomponent(); yourcontrol.pagehandler = this; } public void second_click(object sender, routedeventargs e) { // here } // , control code: public partial class mycontrol : usercontrol { public page pagehandler; public mycontrol() { initializecomponent(); mybutton.hold +=mybutton_hold; } private void mybutton_hold(object sender, system.windows.input.gestureeventargs e) { if (pagehandler mainpage) (pagehandler mainpage).second_click(sender, e); } } the third option pass action control (in case event can private):
// code in mainpage (or page) public mainpage() { initializecomponent(); yourcontrol.myaction = second_click; // setting action of control } private void second_click(object sender, routedeventargs e) { // here } // , control class public partial class mycontrol : usercontrol { public action<object, system.windows.input.gestureeventargs> myaction; public mycontrol() { initializecomponent(); mybutton.hold +=mybutton_hold; } private void mybutton_hold(object sender, system.windows.input.gestureeventargs e) { if (myaction != null) myaction.invoke(sender, e); } }
Comments
Post a Comment