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 For example: file://E:\ImageFile.png |
File system-based resource access. A full path can be supplied. Otherwise, the current working directory is used. |
http/https | http://FullyQualifiedDomainName/IdentifierName
For example: http://www.mydomain.com/ImageFile.png |
Web-based resource access. |
res | res://NativeDll!IdentifierName
For example: res://Sampler!Scenarios.SimpleButton.mcml |
Native Windows resource format that enables access to any resource stored as RCDATA within NativeDll's .RES. |
resx | resx://AssemblyName/ResourceContainerName/IdentifierName
@resx://AssemblyName/ResourceContainerName/IdentifierName #UI_Identifier For example: resx://MyAssembly/MyResources/MyButton
|
Native resource format of.NET.
When referring to a UI element within an MCML resource, use the @ escape symbol. |
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="https://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://TestAssembly/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!" />
Sample Explorer
- Fundamentals > Resource Access
See Also