Search code examples
c#wpfwpf-controlsuielement

Is there any unique identifier for wpf UIElement?


For logging user actions in my WPF forms, I added some global event handlers

I want to log exactly which control fire the event, is there some unique identifier for a wpf UIElement like ClientId in ASP.Net?


Solution

  • Seems I found answer to my question, the answer is No, now way to do that, As noted in MSDN here (http://msdn.microsoft.com/en-us/magazine/dd483216.aspx)

    Notice that the top-level Window control definition does not contain a Name attribute. This is significant because, as we'll see shortly, when you write test automation, an easy way to get a reference to a control using the MUIA library is to access the AutomationId property, which is generated by the compiler from the control's Name attribute. Controls without a XAML Name attribute will not receive an AutomationId property. This idea is a specific, low-level example of the importance of considering application design issues for things such as security, extensibility, and test automation.