skylning

Hi

Everyone,how to get some element on xaml file in WPF/E,maybe ,we can use findName method to get it,but if the element that i will access have not "x:name" attribute or the element " x:name" value is null ,i have no way to get it. at Html DOM,we can get some element by event.srcElement or event.target .at xaml,is so good that if it also have same menthod such as event.target.

My English is poor.

Thanks !!




Re: Silverlight (formerly WPF/E) Developer Issues How to get XAML element without findName method

Luis Miguel Abreu

Hello.

if i'm not mistaken, container elements have a children property which returns the children of that element (just like happens with html). for instance, if you handle the loaded event of the canvas (which normally is used as a top element), you can access its children property to get its direct children (then you only need recursion to get all the controls). btw, do note that using a name is the recommended approach...






Re: Silverlight (formerly WPF/E) Developer Issues How to get XAML element without findName method

skylning

Hi, Luis Miguel Abreu,thank for your answer ,i konow the Children property for a element .you are right.

but ,if a canvas or a element has thousands upon thousands children, it is impossibility to iterator the canvas children.







Re: Silverlight (formerly WPF/E) Developer Issues How to get XAML element without findName method

Luis Miguel Abreu

hello again.

yes, I agree with you.

btw, I've noticed that in the previous post you mention event.srcElement. well, you normally use this in an event handler that's applied to several elements. Methods that handle events in xaml receive a reference to the object that fired the event. So, you can really handle several similar events fired by different objects with the same method.






Re: Silverlight (formerly WPF/E) Developer Issues How to get XAML element without findName method

skylning

Hi

At first ,thanks for your answer.

I know we can binding event for every xaml element,at the case,the event sender is element.

but if a xaml docement has many element,it is impossible to binding event for every element ,if do it,the xaml element size became more bigger and need more time for load xaml document when the page load.and my problem is this:my xaml document has many many elements and it is possible for capture some one in these elements, if i binding event for every element, it is a bad way,.

thanks again.

we all expect the Silverlight betas version ,and hope it became more and more easy use.






Re: Silverlight (formerly WPF/E) Developer Issues How to get XAML element without findName method

Luis Miguel Abreu

hello.

yes, but i think you can relie on the event bubbling to hook up an event on the top element instead of adding several event handlers for its children...