c# - Xaml and Events not Working -


so created basic canvas has event. yet when run code event never hit. im writing in c# metro apps. did wrong?

<grid background="{staticresource applicationpagebackgroundthemebrush}">     <canvas horizontalalignment="left" height="673" verticalalignment="top" width="1346" margin="10,85,0,0" pointermoved="canvas_pointermoved"/> </grid> 

heres c# code

    public mainpage()     {         this.initializecomponent();     }      /// <summary>     /// invoked when page displayed in frame.     /// </summary>     /// <param name="e">event data describes how page reached.  parameter     /// property typically used configure page.</param>     protected override void onnavigatedto(navigationeventargs e)     {     }      private void canvas_pointermoved(object sender, pointerroutedeventargs e)     {         debug.writeline("hit");     } 

you've discovered confusing quirk of canvases. have set background color in order hit tested.

so, example, change code , hit event:

<grid>     <canvas background="blue" horizontalalignment="left" height="673" verticalalignment="top" width="1346" margin="10,85,0,0" pointermove="canvas_pointermoved"/> </grid> 

but, 1 thing you'll need consider whether canvas right kind of panel use. extremely primitive , not used unless need rigidly define layout or micro-optimizing performance.


Comments