locked
ExpanderView Expanded Item event in Windows Phone 7 RRS feed

  • Question

  • Hi,

    Please help me identify what event should i capture for when the user taps on the ExapnderView Exapnded item(s). The ExpanderView is in the ListBox (ListBoxItem) and binded to the collection. I am currently using Tap event of Expanderview but that does not help, Selection_changed event on ListBox also does not work and Gesture Listener fires at the listbox and at the expanded items both.

    Thank You.


    Javeed
    Sunday, January 8, 2012 5:23 AM

Answers

  • Handle Tap event in the ListBoxItem of the ExpanderView.ItemTemplate

    The "sender" in the Tap event handler will be ListBoxItem

    The DataContext property of the ListBoxItem will give you the binding object

    <!-- The ItemTemplate describes the template for all items once the expansion has occured. -->
    <toolkit:ExpanderView.ItemTemplate>
       <DataTemplate>
             <ListBoxItem toolkit:TiltEffect.IsTiltEnabled="True" DataContext="{Binding}" Tap="ExpandedItem_Tap">
                     <StackPanel Margin="0,0,0,17" Width="432">
                             <TextBlock Text="{Binding Path=Property1}" />
                             <TextBlock Text="{Binding Path=Property2}" />
                     </StackPanel>
             </ListBoxItem>
       </DataTemplate>
    </toolkit:ExpanderView.ItemTemplate>

    private void ExpandedItem_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
          ListBoxItem item = sender as ListBoxItem;
          MyClass1 class1 = item.DataContext as MyClass1;
    }

     

    • Marked as answer by Javeed Sunday, January 8, 2012 7:06 PM
    Sunday, January 8, 2012 8:55 AM

All replies

  • Handle Tap event in the ListBoxItem of the ExpanderView.ItemTemplate

    The "sender" in the Tap event handler will be ListBoxItem

    The DataContext property of the ListBoxItem will give you the binding object

    <!-- The ItemTemplate describes the template for all items once the expansion has occured. -->
    <toolkit:ExpanderView.ItemTemplate>
       <DataTemplate>
             <ListBoxItem toolkit:TiltEffect.IsTiltEnabled="True" DataContext="{Binding}" Tap="ExpandedItem_Tap">
                     <StackPanel Margin="0,0,0,17" Width="432">
                             <TextBlock Text="{Binding Path=Property1}" />
                             <TextBlock Text="{Binding Path=Property2}" />
                     </StackPanel>
             </ListBoxItem>
       </DataTemplate>
    </toolkit:ExpanderView.ItemTemplate>

    private void ExpandedItem_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
          ListBoxItem item = sender as ListBoxItem;
          MyClass1 class1 = item.DataContext as MyClass1;
    }

     

    • Marked as answer by Javeed Sunday, January 8, 2012 7:06 PM
    Sunday, January 8, 2012 8:55 AM
  • Hi Naveed,

    Thank you for your prompt reply, this works wonder!

    Regards.

    Javeed


    Javeed
    Sunday, January 8, 2012 7:05 PM
  • This forum is for writing Metro style apps on the Windows 8 Developer Preview.

    Please post questions about Windows Phone 7 development on the Windows Phone 7 forums at the App Hub.

    --Rob

    Sunday, January 8, 2012 8:03 PM
    Moderator