1

I am trying to add event handlers to an element, but it's not successful... So I would like to be able to verify whether or not a handler is actually applied. I.e. Console.WriteLine(tile.Element.HandlerX.ToString()).

I know I am targeting the correct element as it other element manipulation does work.

Is there any way to do this?

Best regards!

Solution for me: I did not figure out how to do what I required. But I added a button, and the button didn't work, so I realized that probably the Frame is not working. And I remembered that once upon a time, I had turned off IsHitTestVisible. Thus, the mouse pointer could not interact with the elements I wanted to interact with.

Question Solution: So the question is quite unanswered, apart from @McNets comment for reflection, but I am unaware on how to implement that. Here's the link to the thread that brought a similar question: How to easilly see number of event subscriptions while debugging? But as it stands, the reason for me needing this is no longer relevent.

Bishiba
  • 103
  • 8
  • 1
    Please note that "the UWP/WPF way of doing things" is binding dependency properties rather than event handlers. – Ben Voigt Apr 05 '22 at 15:49
  • As it stands I am able to add event handlers to other elements. I.e. inventoryIcon.Tapped += new TappedEventHandler(inventoryItem_Tapped);. But with my current situation, I am unable to do the same(for whatever reason). But I am quite new to C# programming so I do appreciate the information but am still hopeful that I'll get a solution. – Bishiba Apr 05 '22 at 15:51
  • 1
    Maybe better check for null. `if (Element.HandlerX != null)` or [the number of event subscriptions](https://stackoverflow.com/questions/24003458/how-to-easilly-see-number-of-event-subscriptions-while-debugging) – McNets Apr 05 '22 at 17:22
  • @McNets The issue with this lies that you can't do for example `Element.Tapped`, the only way to use an event handler is to do it with a += och -=, i.e: `Element.Tapped += new TappedEventHandler(Element_Tapped);` I think I might need to make a new thread explaining my situation as a whole :( – Bishiba Apr 05 '22 at 17:30
  • 1
    You can use reflection to seach for all EventHandlers in your class. – McNets Apr 05 '22 at 17:42
  • @McNets Do you have a source or tip for how to do this? I have not used reflections to much – Bishiba Apr 05 '22 at 18:24
  • 1
    Maybe [this](https://stackoverflow.com/a/1121516/3270427) helps – McNets Apr 05 '22 at 19:54
  • @McNets can you make it an answer so I can mark it as the answer? – Bishiba Apr 06 '22 at 11:12
  • 1
    I'm sorry but I can't just copy it here. – McNets Apr 06 '22 at 12:25
  • @McNets Can you post it as a reference I meant. Perhaps that's not allowed either? – Bishiba Apr 06 '22 at 12:37
  • No, because if I use another answer this question should be closed as a duplicated. – McNets Apr 06 '22 at 12:38
  • @McNets Ah alright, I could look up the following myself, but it's a quick little follow-up and you seem to be "in-the-know" with 9400+ reputation compared to my measly 43... Can I edit the post and put the link as the solution or will it still be counted as a duplicate? – Bishiba Apr 07 '22 at 11:30
  • You can edit and add the link. – McNets Apr 07 '22 at 14:09

0 Answers0