Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Media Elements usage based on some index value that matches with media element name

Media Elements usage based on some index value that matches with media element name

Scheduled Pinned Locked Moved WPF
helptutorialdatabasedesign
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pavanip
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • P pavanip

      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

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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:

      P 1 Reply Last reply
      0
      • M Mark Salsbery

        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:

        P Offline
        P Offline
        pavanip
        wrote on last edited by
        #3

        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.

        M 1 Reply Last reply
        0
        • P pavanip

          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.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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:

          P 1 Reply Last reply
          0
          • M Mark Salsbery

            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:

            P Offline
            P Offline
            pavanip
            wrote on last edited by
            #5

            Hi Mark, Thank you very much for your clear explanation.I solved my problem through your explanation.Now I got how to use media element references using list and dictionary.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups