Kanzi Framework  3.9.0
Kanzi Studio API
ResourceReference< T > Class Template Reference

Create resource references. More...

Inheritance diagram for ResourceReference< T >:
[legend]
Collaboration diagram for ResourceReference< T >:
[legend]

Public Member Functions

 ResourceReference (string resourceID)
 Creates a resource reference using a resource ID. More...
 
 ResourceReference (T resource)
 Creates a resource reference. More...
 
GetTarget (Node context)
 Gets the target resource to which the resource reference points. More...
 
- Public Member Functions inherited from ProjectItemReference< T >
GetTarget (Node context)
 Gets the node to which a relative node reference points. More...
 

Additional Inherited Members

- Properties inherited from ProjectItemReference< T >
bool IsAbsoluteReference [get]
 Gets whether a project item reference is an absolute reference. More...
 

Detailed Description

Create resource references.

Template Parameters
T
Type Constraints
T :class 
T :NodeResource 

Constructor & Destructor Documentation

◆ ResourceReference() [1/2]

ResourceReference ( string  resourceID)
inline

Creates a resource reference using a resource ID.

Parameters
resourceIDThe resource ID of the resource to which you want to point.

Examples

To create a resource reference using a resource ID:

public void Execute(PluginCommandParameter parameter)
{
// Create a resource. For example, create a texture which uses the DefaultTextureImage.png.
// Get the Library > Resource Files > Images directory.
var imageDirectory = studio.ActiveProject.ImageDirectory;
// Get the DefaultTextureImage.png image stored in the Images directory.
var defaultTextureImage = imageDirectory.GetItemByName("DefaultTextureImage.png") as ImageFile;
// Get the Library > Materials and Textures > Textures library.
var textureLibrary = studio.ActiveProject.TextureLibrary;
// Create a texture in the Textures library.
var myTexture = studio.ActiveProject.CreateProjectItem<SingleTexture>(textureLibrary.GenerateUniqueChildName("My Texture"), textureLibrary);
// Set the Image property of the texture, which you created, to the DefaultTextureImage.png image.
myTexture.Set(myTexture.PropertyTypes.TextureImage, defaultTextureImage);
// Get the Screen node. The Screen node by default has a resource dictionary.
var screenNode = studio.ActiveProject.GetProjectItem("Screens/Screen/") as Node;
// In the resource dictionary of the Screen node create a resource entry with the resource ID ResourceIDOfMyTexture,
// and set it to point to the texture that you created.
screenNode.ResourceDictionary.CreateResourceEntry("ResourceIDOfMyTexture", myTexture);
// Get the Screens/Screen/RootPage node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// In the RootPage node create an Image node.
var imageNode = studio.ActiveProject.CreateProjectItem<Image2D>(rootPage.GenerateUniqueChildName("Image"), rootPage);
// In the Image node set the Image property to a resource reference which uses the resource ID ResourceIDOfMyTexture
// to point to the My Texture texture.
imageNode.Set(Properties.Image2DImage, new ResourceReference<Texture>("ResourceIDOfMyTexture"));
}

◆ ResourceReference() [2/2]

ResourceReference ( resource)
inline

Creates a resource reference.

Parameters
resourceThe resource to which you want to point.

Examples

To create a resource reference that points to a texture resource:

public void Execute(PluginCommandParameter parameter)
{
// Create a resource. For example, create a texture which uses the DefaultTextureImage.png.
// Get the Library > Resource Files > Images directory.
var imageDirectory = studio.ActiveProject.ImageDirectory;
// Get the DefaultTextureImage.png image stored in the Images directory.
var defaultTextureImage = imageDirectory.GetItemByName("DefaultTextureImage.png") as ImageFile;
// Get the Library > Materials and Textures > Textures library.
var textureLibrary = studio.ActiveProject.TextureLibrary;
// Create a texture in the Textures library.
var myTexture = studio.ActiveProject.CreateProjectItem<SingleTexture>(textureLibrary.GenerateUniqueChildName("My Texture"), textureLibrary);
// Set the Image property of the texture, which you created, to the DefaultTextureImage.png image.
myTexture.Set(myTexture.PropertyTypes.TextureImage, defaultTextureImage);
// Get the Screens/Screen/RootPage node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// In the RootPage node create an Image node.
var imageNode = studio.ActiveProject.CreateProjectItem<Image2D>(rootPage.GenerateUniqueChildName("Image"), rootPage);
// In the Image node set the Image property to a resource reference that points to the My Texture texture.
imageNode.Set(Properties.Image2DImage, new ResourceReference<Texture>(myTexture));
}

Member Function Documentation

◆ GetTarget()

T GetTarget ( Node  context)
inline

Gets the target resource to which the resource reference points.

Parameters
contextThe node that is referencing to the resource.
Returns
The resource to which the resource reference points.