Tapped event on grid control RRS feed

  • Question

  • Hello

    I have the following Xaml script

     <Grid Background="Black" Name="LayoutRoot">
          <Grid Width="500" Height="500" Background="Blue" Name="grid"/>
          <Canvas Background="Transparent" Name="canvas" Width="500" Height="500"/>

    now I want to handle Tapped event on both grid and canvas , I noticed that this event fired only on canvas , and didn't fire on grid

    why I get this behavior?, and how can I fire the event in both

    Sunday, December 30, 2012 8:54 AM


  • Consider:

        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <Grid Background="Black" Name="LayoutRoot" Tapped="LayoutRoot_Tapped_1">
                <Grid Width="500" Height="500" Background="Blue" Name="grid" Tapped="grid_Tapped_1"/>
                <!--<Canvas Background="{x:Null}" Name="canvas" Width="500" Height="500" Tapped="canvas_Tapped_1"/>-->
                <Canvas Background="Transparent" Name="canvas" Width="500" Height="500" Tapped="canvas_Tapped_1"/>

    Only one of the children, depending on 'Transparent' or '{x:Null}' setting, gets the tapped event.

    However, in both cases, the 'LayoutRoot' obtains the tapped event from one of its children. So, it is the 'LayoutRoot' that will be in charge of informing both children about the event, e.g. accessing them thru the UIElementCollection coll = LayoutRoot.Children. This must be programmed in the 'LayoutRoot_Tapped_1' event handler
    • Edited by ForInfo Sunday, December 30, 2012 1:36 PM
    • Proposed as answer by Jesse Jiang Wednesday, January 2, 2013 6:26 AM
    • Marked as answer by Jesse Jiang Monday, January 7, 2013 6:19 AM
    Sunday, December 30, 2012 1:33 PM