Media Elements usage based on some index value that matches with media element name
-
Hi, I am developing one application in that I have more than 20 media elements.Here is the example for 5 media elements mp1,mp2,mp3,mp4,mp5. And i am using i value from 1 to 20 based on the i value i have to use that corresponding media element.If i value is 2 i have to use mp2 and assign path to that mp2 source from code behind. Those all media elements are created by default through design.Please can anybody help me how to resolve this problem or any suggestions to achieve this task. Thanks in Advance Pavani
-
Hi, I am developing one application in that I have more than 20 media elements.Here is the example for 5 media elements mp1,mp2,mp3,mp4,mp5. And i am using i value from 1 to 20 based on the i value i have to use that corresponding media element.If i value is 2 i have to use mp2 and assign path to that mp2 source from code behind. Those all media elements are created by default through design.Please can anybody help me how to resolve this problem or any suggestions to achieve this task. Thanks in Advance Pavani
Store references to each media element in a collection or array. If they are stored in order, you can simple use an index to access the references.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Store references to each media element in a collection or array. If they are stored in order, you can simple use an index to access the references.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Hi Merk thank you for your response.Can you please explain me clearly how to create references for media elements and how to store those references in array or collection because i am new to develpoment.
Here's two examples, using two different types of collections... Using a Dictionary<>
using System;
using System.Collections.Generic;
using System.Windows.Controls;// Make a dictionary of MediaElements Dictionary<int, MediaElement> mediaElementDictionary = new Dictionary<int, MediaElement>(); // Add MediaElements to the dictionary mediaElementDictionary.Add(1, mp1); mediaElementDictionary.Add(2, mp2); ... // Access MediaElements in the dictionary int i = 1; MediaElement mediaelement; if (mediaElementDictionary.TryGetValue(i, out mediaelement)) { // use mediaelement }
Using a List<>
using System;
using System.Collections.Generic;
using System.Windows.Controls;// Make a list of MediaElements List<MediaElement> mediaElementList = new List<MediaElement>(); // Add MediaElements to the list mediaElementList.Add(mp1); mediaElementList.Add(mp2); ... // Access MediaElements in the list int i = 1; // Note: i is 1 to 20, indexes are zero-based so we have to subtract 1 MediaElement mediaelement = mediaElementList\[i - 1\]; // use mediaelement
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Here's two examples, using two different types of collections... Using a Dictionary<>
using System;
using System.Collections.Generic;
using System.Windows.Controls;// Make a dictionary of MediaElements Dictionary<int, MediaElement> mediaElementDictionary = new Dictionary<int, MediaElement>(); // Add MediaElements to the dictionary mediaElementDictionary.Add(1, mp1); mediaElementDictionary.Add(2, mp2); ... // Access MediaElements in the dictionary int i = 1; MediaElement mediaelement; if (mediaElementDictionary.TryGetValue(i, out mediaelement)) { // use mediaelement }
Using a List<>
using System;
using System.Collections.Generic;
using System.Windows.Controls;// Make a list of MediaElements List<MediaElement> mediaElementList = new List<MediaElement>(); // Add MediaElements to the list mediaElementList.Add(mp1); mediaElementList.Add(mp2); ... // Access MediaElements in the list int i = 1; // Note: i is 1 to 20, indexes are zero-based so we have to subtract 1 MediaElement mediaelement = mediaElementList\[i - 1\]; // use mediaelement
Mark Salsbery Microsoft MVP - Visual C++ :java: