Get control child control in Silverlight

Source: Internet
Author: User
Tags silverlight

As a question:, look directly at the code:

/// <summary>        ///finds and returns the first child element of the same name/// </summary>        /// <typeparam name= "T" >the type of child control you want to find</typeparam>        /// <param name= "obj" >The type of control that needs to find the next face control</param>        /// <param name= "ChildName" >the name of the child control</param>        /// <returns></returns>         Public StaticT findfirstvisualchild<t> (DependencyObject obj,stringChildName)whereT:dependencyobject { for(inti =0; I < Visualtreehelper.getchildrencount (obj); i++) {DependencyObject child=visualtreehelper.getchild (obj, i); if(Child! =NULL&& Child isT && Child. GetValue (System.Windows.FrameworkElement.NameProperty). ToString () = =childname) {                    return(T) child; }                Else{T Childofchild= findfirstvisualchild<t>(Child, ChildName); if(Childofchild! =NULL)                    {                        returnChildofchild; }                }            }            return NULL; }

This is probably the case, the parameters of the above method and so on things are very clear. This time the demand is to click in the ListBox, you need to determine which one to click, you need to pass the ID to the second page to determine what the second page shows. And my listbox is all tile (Windows Phone), so I'm going to get the ID I need by clicking on the event below.

Private voidButton_click_1 (Objectsender, RoutedEventArgs e) {Tile B= (Sender) asTile; //finds the value in TextBlock that is hidden under control c4f, which is the value of the IDTextBlock C = iscau.tools.domehandle.findfirstvisualchild<textblock> (b,"Mark"); Navigationservice.navigate (NewUri ("/syncfood/foodmenu.xaml?id="+C.text, urikind.relative)); }

Get control child control in Silverlight

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.