locked
How to get item's ContentTemplateRoot of listview in itemclick event? RRS feed

  • Question

  • How to get  item's ContentTemplateRoot of listview in itemclick event?

    I can get ContentTemplateRoot in ContainerContentChanging fuction like below

    -----------------------------------------------------------------------------------------------------

            private void ListViewItem_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
            {
              
                ViewItemCtrl ViewItem = args.ItemContainer.ContentTemplateRoot as ViewItemCtrl;
             }

    -----------------------------------------------------------------------------------------------------


    i want to get it in itemclick event function

    -----------------------------------------------------------------------------------------------------

            private void ListView_ItemClick(object sender, ItemClickEventArgs e)
            {
              
                Item Item = (Item)e.ClickedItem;

                // ViewItemCtrl ViewItem   -> how to get it?
            }

    -----------------------------------------------------------------------------------------------------


    • Edited by estmob Monday, December 8, 2014 9:08 AM
    Monday, December 8, 2014 9:08 AM

Answers

  • for this scenario, you need use another way to instead of "Item Click",

    like

     <ListView x:Name="liveview" ContainerContentChanging="liveview_ContainerContentChanging" >
                <ListView.ItemTemplate >
                    <DataTemplate >
                        <Border BorderBrush="Red" BorderThickness="4" Tapped="Border_Tapped" >
                            <TextBlock Text="{Binding Title}" FontSize="24"/>
                        </Border>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
      private void Border_Tapped(object sender, TappedRoutedEventArgs e)
            {
                ((Border)sender).BorderBrush = new SolidColorBrush(Colors.Blue);
            } 



    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Monday, December 8, 2014 3:58 PM