GetItemByName

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the MediaAttribute for the collection with the Name that matches the specified string.

retval = object.GetItemByName(name)

Arguments

name

string

The name of the MediaAttribute to get from the collection.

Return Value

Type: MediaAttribute

The MediaAttribute with the Name property equal to the specified string if found; otherwise, null.

Managed Equivalent

In managed code, the Attributes collection is a Dictionary<TKey, TValue>.

Remarks

GetItemByName is a convenience method that retrieves media attributes without requiring you to iterate the entire collection.

GetItemByName is a specific implementation of the MediaAttributeCollection collection. It does not exist on other collections (for example, the collection held by Canvas.Children) and works specifically on the Name property of a MediaAttribute. This name is not the same concept as the Name property that is used to identify a XAML element for retrieval by FindName in run-time code.

Example

The following JavaScript example shows how to retrieve a MediaAttribute by name from the Attributes property of a MediaElement that has a Source (MediaElement) property set to an ASX playlist file. It then displays the Name and Value properties of the MediaAttribute.

function onMediaOpened(sender, args) {
    // Variable to hold the MediaAttribute.
    var attribute;
   
    // Get the MediaAttribute named Title.
    try
    {
        var attributesCollection = sender.Attributes;
        attribute = attributesCollection.getItemByName("Title");
    }
    catch(errorObj)
    {
        alert(errorObj.message);
    }
    
    // Display the value of the MediaAttribute.
    if(attribute != null)
    {
      alert("The title of the track is: " + attribute.value);
    }
}

See Also

Reference