Click to Rate and Give Feedback
MSDN
MSDN Library
Programming Guide
MCML Basics
 Using Resources in MCML

  Switch on low bandwidth view
Using Resources in MCML

In markup, you can refer to resources (such as images, sounds, MCML files, and Web sites) using a uniform resource identifier (URI). The following resource types are supported for MCML:

Type Format Description
file file://DriveLetter:\FolderName\IdentifierName

file://IdentifierName

File system-based resource access. A full path can be supplied. Otherwise, the current working directory is used.

For example:

file://E:\MyButton.mcml

http/https http://FullyQualifiedDomainName/IdentifierName Web-based resource access.

For example:

http://www.mydomain.com/MyButton.mcml

Note   You must use absolute paths because relative paths are not supported.

res res://NativeDll!IdentifierName Native Windows resource format that enables access to any resource stored as RCDATA within NativeDll's .RES.

For example:

res://McmlSampler!Scenarios.SimpleButton.mcml

resx resx://AssemblyName/ResourceContainerName/IdentifierName Native resource format of .NET.
  • AssemblyName can be a partial or strong name.
  • ResourceContainerName is the name of the resources file within the assembly.
  • IdentifierName is the name of the resource.

For example:

resx://MyAssembly/MyResources/MyButton.mcml


External MCML markup can be referenced from an MCML file by specifying the resource path within your xmlns statements:

xmlns:sb="file://Scenarios.SimpleButton.mcml"
xmlns:sb="http://www.contoso.com/Scenarios.SimpleButton.mcml"

Markup access would be of the form: <sb:SimpleButton/>

The res:// protocol is designed to load Microsoft Win32 resources, with the following limitations:

  • The res:// protocol can be used to load resources from a managed binary, but that managed binary must be strong-name signed, and located in the global assembly cache (GAC).
  • The syntax is res://myassembly!myresource.extension. In this scenario, myassembly is not given a file extension, so you cannot have a managed DLL and EXE with the same name and be able to load resources from both of them.
  • In res://myassembly!myresource.extension, myassembly can be a short assembly name or a fully-qualified assembly identity.
  • The res:// protocol can also be used to load resources from an unmanaged binary, but it is limited to unmanaged DLLs. Loading resources from an unmanaged EXE using the res:// protocol is not supported.

The resx:// protocol is designed to load resources from .resx files that are embedded into managed assemblies, with the following limitations:

  • The resx:// protocol is used to load resources from a managed assembly, which must be strong-name signed and located in either %windir%\ehome or the global assembly cache (GAC).
  • In the syntax resx://myassembly/myresourcefile/myresourceidentifier, the myassembly parameter does not have a file extension, so you cannot have a managed DLL and EXE with the same name and be able to load resources from both of them.

When referencing types or methods in an assembly, you should define an xmlns prefix that represents the entire namespace that you want to use rather than only the assembly name.

For example, if you have an assembly named TestAssembly that has a class called TestClass, and TestClass has a method called TestMethod, you would use the following syntax to refer to the TestMethod:

xmlns:myclass="assembly://TestResource/TestClass"
...
<Text Content="[RepeatedItem!myclass:TestMethod.ToString]" />

As another example, if you want to use the .NET Framework System.String object, you would use the following syntax:

xmlns:cor="assembly://MSCorlib/System" 
...
<cor:String Name="MyString" String="Hello World!"/>

The following example shows how to access resources in MCML (for additional examples, see the Media Center Markup Language Sampler):

<Mcml
  xmlns="http://schemas.microsoft.com/2006/mcml"
  xmlns:sb="res://McmlSampler!Scenarios.SimpleButton.mcml">
  <!-- The following sample demonstrates resource access in different scenarios. -->
  <UI Name="ResourceAccess">
    <Locals>
      <Command Name="PlayIt" Description="Let's hear it!"/>
    </Locals>
    <Rules>
      <Changed Source="[PlayIt.Invoked]">
        <Actions>
          <!-- Sound stored as a RESX resource. -->
          <PlaySound Sound="resx://McmlSampler/McmlSampler/Intro"/>
          <PlayAnimation Target="[Logo]">
            <Animation>
              <Animation CenterPointPercent=".5,.5,1">
                <Keyframes>
                  <ScaleKeyframe Time="0" Value="1,1,1"/>
                  <ScaleKeyframe Time=".35" Value=".5,.5,1"/>
                  <ScaleKeyframe Time=".4" Value="2,2,1"/>
                  <ScaleKeyframe Time="4" Value="1,1,1"/>
                  <RotateKeyframe Time="0" Value="0deg;0,0,1"/>
                  <RotateKeyframe Time="4" Value="720deg;0,0,1"/>
                </Keyframes>
              </Animation>
            </Animation>
          </PlayAnimation>
        </Actions>
      </Changed>
    </Rules>
    <Content>
      <Panel>
        <Layout>
          <FlowLayout Orientation="Vertical" ItemAlignment="Center" Spacing="20,0"/>
        </Layout>
        <Children>
          <!-- Image stored as a RESX resource. -->
          <Graphic Name="Logo" Content="resx://McmlSampler/McmlSampler/MediaCenter"/>
          <!-- SimpleButton MCML from a RES resource (using an xmlns statement from above). -->
          <sb:SimpleButton Command="[PlayIt]"/>
        </Children>
      </Panel>
    </Content>
  </UI>
</Mcml>

See Also

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker