Custom MediaElement

602 Views Asked by At

I am currently using some MediaElements in an application I am creating. I am dynamically creating them and adding them to a wrap panel.

The problem is I need to be able to add a key to them so I can go back and locate a specific one.

I was going to inherit from the MediaElement and just add the key as a member. Unfortunately I can't do this because it's a sealed class.

So I tried to create a class containing a MediaElement and the key but I can't add that to the GUI since its not a UIElement.

Is there anyway I can do this? I just need to be able to add MediaElements and them be able to go back and find them later so I can modify or remove them.

2

There are 2 best solutions below

0
On BEST ANSWER

There is such way. Add Dictrionary <string, MediaElement> to your form. When adding new media element, add it to the dictionary either. When you'll need to access the MediaElement you can query it from dictionary by using it's key name. You'll get the reference to your element that is at the same time in dictionary and on GUI.

And when deleting from GUI, don't forget to delete element from dictionary either.

0
On

Handling it with the dictionary is a good idea, but you will have to maintain its state as and when you add or remove mediaelements from UI. As a second option,you can also inherit your custom class with a UserControl and add the mediaElement in it as a child. That way you will be able to add your own class with key and handle it as per your own logic