Public Member Functions | Properties | Events | List of all members
ProjectItem Interface Reference

Access nodes and resources in a Kanzi Studio project. More...

Inheritance diagram for ProjectItem:
ChildContainer

Public Member Functions

void AddProperty (string propertyName)
 Adds a property to an item. More...
 
void AddProperty (Property property)
 
void BeginBatchModification (string batchName)
 
bool CanAddProperty (string propertyName)
 
bool CanAddProperty (Property property)
 
void CommitBatchModification ()
 
bool Delete ()
 Deletes a project item. More...
 
void DeregisterThumbnailUser (object user)
 Deregisters a registerd thumbnail user. More...
 
IEnumerable< Property > GetAddableProperties ()
 Gets a list of properties which you can add to an item. More...
 
GetAncestor< T > ()
 Gets the nearest item of given type in the parent tree. More...
 
ProjectItem GetChild (string childName)
 Gets the child item of the current item with the given name. More...
 
GetChild< T > (string childName)
 Gets the child item of the current item with the given name and type. More...
 
int GetChildIndex (ProjectItem child)
 
IEnumerable< Property > GetContextProperties ()
 
IEnumerable< Property > GetFixedProperties ()
 
IEnumerable< Property > GetFrequentlyAddedProperties ()
 
ProjectItem GetProjectItemByPath (string path)
 
string GetRelativeProjectPathTo (ProjectItem anotherItem)
 
IEnumerable< Property > GetRemovableProperties ()
 Gets a list of properties which you can remove from an item. More...
 
BitmapSource GetThumbnail (int width, int height, bool showChildren, bool showFullScreen, Node contextNode)
 Gets the thumbnail image for a project item. More...
 
BitmapSource GetThumbnail (int width, int height, bool showChildren, bool showFullScreen, Node contextNode, float[] letterboxColorRGBA)
 Gets the thumbnail image for a project item. More...
 
IEnumerable< ProjectItemGetTreeItemsAsList ()
 Enumerates the items under this ProjectItem including this item itself, children, and grand children. More...
 
bool HasProperty (string propertyName)
 Checks whether an item has a specific property. More...
 
bool HasProperty (Property property)
 
bool IsPropertyReadOnly (Property property)
 
void RegisterThumbnailUser (object user, uint width, uint height, bool showChildren, bool showFullScreen, Node contextNode)
 Registers a user for the thumbnail images for a project item. More...
 
void RemoveProperty (string propertyName)
 Removes a property from an item. More...
 
void RemoveProperty (Property property)
 
void SetChildIndex (ProjectItem child, int index)
 
void SetPropertyReadOnlyStatus (Property property, bool?value)
 
void UpdateValidity ()
 Recalculates the validity the item. More...
 
- Public Member Functions inherited from ChildContainer
string GenerateUniqueChildName (string defaultName)
 Generates a unique name. More...
 
string GetInvalidityReasonOfNewName (string newName)
 Returns the reason why the passed name is not valid. More...
 

Properties

IEnumerable< ProjectItemChildren [get]
 Gets all child items of a project item. More...
 
string HelpHeading [get]
 
string IconLocation [get]
 
object IconModifier [get, set]
 
string InvalidityReason [get]
 
bool IsDeleted [get]
 
bool IsHidden [get, set]
 
bool IsReadOnly [get, set]
 
bool IsValidState [get]
 
string KzbUrl [get]
 Gets the .kzb URL of a project item. More...
 
string Name [get, set]
 Gets and sets the name of a project item. More...
 
ProjectItem Parent [get, set]
 
string Path [get]
 
Project Project [get]
 Gets the project in which this item is located. More...
 
Type ProjectItemType [get]
 
object this[Property property] [get, set]
 
object this[string propertyName] [get, set]
 
string ToolTip [get]
 
string TypeDisplayName [get]
 Gets the type of a project item. More...
 

Events

EventHandler< CollectionChangedEventArgs< ProjectItem > > ChildCollectionChanged
 
EventHandler< DeletedEventArgs > Deleted
 
EventHandler< CollectionChangedEventArgs< ProjectItem > > DescendantChildCollectionChanged
 
EventHandler< DeletedEventArgs > DescendantDeleted
 
EventHandler< DynamicPropertyChangedEventArgs > DescendantDynamicPropertyChanged
 
EventHandler< ParentChangedEventArgs > DescendantParentChanged
 
EventHandler< CollectionChangedEventArgs< string > > DescendantPropertyCollectionChanged
 
EventHandler< DynamicPropertyChangedEventArgs > DynamicPropertyChanged
 
EventHandler< ParentChangedEventArgs > ParentChanged
 
EventHandler< PathChangedEventArgs > PathChanged
 
EventHandler< DynamicPropertyChangedEventArgs > PreviewDescendantDynamicPropertyChanged
 
EventHandler< DynamicPropertyChangedEventArgs > PreviewDynamicPropertyChanged
 
EventHandler< CollectionChangedEventArgs< string > > PropertyCollectionChanged
 
EventHandler< ReplaceEventArgs > Replacing
 
EventHandler ThumbnailChanged
 
EventHandler ValidityChanged
 

Detailed Description

Access nodes and resources in a Kanzi Studio project.

For example, use this class to get a node, add, remove, or set its properties, find out about its relations to other nodes, get notifications about changes to that node, and to delete the node.

Member Function Documentation

void AddProperty ( string  propertyName)

Adds a property to an item.

When you add a property to a node, the initial value of the property is the default value set for that property. Use the Set function to set the value of a property.

Parameters
propertyNameThe name of the property to add.
See also
RemoveProperty(string), RemoveProperty(Property)

Examples

To add a property to a node:

// To add a property to a node first get or create that node, and then use the AddProperty function to add the property.
public void Execute(PluginCommandParameter parameter)
{
// Get the parent node where you first create a node.
var rootPage = studio.Project.GetProjectItem("Screens/Screen/RootPage");
// Create a Page node named "My Page".
var myPage = studio.Project.CreateProjectItem<Page>("My Page", rootPage);
// Add the Background Brush property to the "My Page" node you created in the previous line.
myPage.AddProperty(Properties.Node2DBackgroundBrush);
}
bool Delete ( )

Deletes a project item.

Returns
True when it deletes the item successfully, otherwise false.

Examples

To delete a node from the scene graph:

// To delete a node you first have to get it, and then use the Delete function to delete it.
public void Execute(PluginCommandParameter parameter)
{
// Get the parent node of the node you want to delete.
var rootNode = studio.Project.GetProjectItem("Screens/Screen/RootPage");
// Get the node you want to delete.
var defaultViewport2D = rootNode.GetChild("Viewport 2D");
// Delete the node.
defaultViewport2D.Delete();
}
void DeregisterThumbnailUser ( object  user)

Deregisters a registerd thumbnail user.

Parameters
userThe registered thumbnail user you want to deregister.
See also
GetThumbnail(int, int, bool, bool, Node), RegisterThumbnailUser
IEnumerable<Property> GetAddableProperties ( )

Gets a list of properties which you can add to an item.

Returns
A list of properties as Property object types which you can add to an item.
See also
GetRemovableProperties, AddProperty(string), AddProperty(Property)

Examples

To get a list of properties which you can add to a node:

public void Execute(PluginCommandParameter parameter)
{
// Get the node for which you want to get a list of properties which you can add.
var rootPage = studio.Project.GetProjectItem("Screens/Screen/RootPage");
// Get the list of all properties which you can add, iterate through the list, and print the name of each property.
foreach (Property property in rootPage.GetAddableProperties())
{
// Print the name of all properties which you can add to the Kanzi Studio Log window.
studio.Log(property.Name);
}
}
T GetAncestor< T > ( )

Gets the nearest item of given type in the parent tree.

The parent tree starts from the item itself, then this.Parent, then this.Parent.Parent, and so on.

Template Parameters
TThe type looked for
Type Constraints
T :class 
T :ProjectItem 
ProjectItem GetChild ( string  childName)

Gets the child item of the current item with the given name.

For example, use this function to get the child nodes of the current node, or items in any of the Kanzi Studio project libraries, such as Brushes, Textures, Styles, and so on.

Parameters
childNameThe name of the child item you want to get with this function.
Returns
The child item with matching name, or null if not found.
See also
Children

Examples

To get a node:

// To get a node you first have to get its parent node, and then use the GetChild function to get its child node.
public void Execute(PluginCommandParameter parameter)
{
// Get the parent node of the node you want to get.
var parentNode = studio.Project.GetProjectItem("Screens/Screen");
// Get the RootPage node in the Screens/Screen node.
var rootPage = parentNode.GetChild("RootPage");
}

To get a resource:

// To get a resource you first have to get the library where the resource is stored,
// and then use the GetChild function to get the resource in that library.
public void Execute(PluginCommandParameter parameter)
{
// Get the Brushes library which stores all the brushes in a Kanzi Studio project.
var brushLibrary = studio.Project.BrushLibrary;
// Get the DefaultBackground texture brush from the Brushes library.
var defaultBackground = brushLibrary.GetItemByName("DefaultBackground");
}
T GetChild< T > ( string  childName)

Gets the child item of the current item with the given name and type.

For example, use this function to get the child nodes of the current node, or items in any of the Kanzi Studio project libraries, such as Brushes, Textures, Styles, and so on.

Template Parameters
TThe type of the item you want to get with this function.
Parameters
childNameThe name of the child item you want to get with this function.
Returns
The child item with matching name and type, or null if not found.
See also
Children

Examples

To get a node:

// To get a node you first have to get its parent node, and then use the GetChild function to get its child node.
public void Execute(PluginCommandParameter parameter)
{
// Get the parent node of the node you want to get.
var parentNode = studio.Project.GetProjectItem("Screens/Screen");
// Get the RootPage node in the Screens/Screen node.
var rootPage = parentNode.GetChild<Page>("RootPage");
}

To get a resource:

// To get a resource you first have to get the library where the resource is stored,
// and then use the GetChild function to get the resource in that library.
public void Execute(PluginCommandParameter parameter)
{
// Get the Brushes library which stores all the brushes in a Kanzi Studio project.
var brushLibrary = studio.Project.BrushLibrary;
// Get the DefaultBackground texture brush from the Brushes library.
var defaultBackground = brushLibrary.GetChild<Brush>("DefaultBackground");
}
Type Constraints
T :ProjectItem 
IEnumerable<Property> GetRemovableProperties ( )

Gets a list of properties which you can remove from an item.

Returns
A list of properties as Property object types which you can remove from an item.
See also
GetAddableProperties, RemoveProperty(string), RemoveProperty(Property)

Examples

To get a list of properties which you can remove from a node:

public void Execute(PluginCommandParameter parameter)
{
// Get the node for which you want to get a list of properties which you can remove.
var rootPage = studio.Project.GetProjectItem("Screens/Screen/RootPage");
// Get the list of all properties which you can remove, iterate through the list, and print the name of each property.
foreach (Property property in rootPage.GetRemovableProperties())
{
// Print the name of all properties which you can remove to the Kanzi Studio Log window.
studio.Log(property.Name);
}
}
BitmapSource GetThumbnail ( int  width,
int  height,
bool  showChildren,
bool  showFullScreen,
Node  contextNode 
)

Gets the thumbnail image for a project item.

If you use the RegisterThumbnailUser function, Kanzi makes the image availabe in cache for quick retrival, otherwise the rendering of the thumbnail takes more time.

Parameters
widthThe width of the thumbnail image.
heightThe height of the thumbnail image.
showChildrenIf set to true [show children].
showFullScreenIf set to true [show full screen].
contextNodeThe context node for resources, such as states, that require a node to display themselves in.
Returns
The thumbnail image of the project item.
BitmapSource GetThumbnail ( int  width,
int  height,
bool  showChildren,
bool  showFullScreen,
Node  contextNode,
float[]  letterboxColorRGBA 
)

Gets the thumbnail image for a project item.

If you use the RegisterThumbnailUser function, Kanzi makes the image availabe in cache for quick retrival, otherwise the rendering of the thumbnail takes more time.

Parameters
widthThe width of the thumbnail image.
heightThe height of the thumbnail image.
showChildrenIf set to true [show children].
showFullScreenIf set to true [show full screen].
contextNodeThe context node for resources, such as states, that require a node to display themselves in.
letterboxColorRGBALetter box color
Returns
The thumbnail image of the project item.
IEnumerable<ProjectItem> GetTreeItemsAsList ( )

Enumerates the items under this ProjectItem including this item itself, children, and grand children.

Returns
bool HasProperty ( string  propertyName)

Checks whether an item has a specific property.

For example, use this function to check for the presence of a specific property before trying to add or remove that property from an item.

Parameters
propertyNameThe name of the property the presence of which you want to check.
Returns
True when the item has the specified property, otherwise false.
See also
AddProperty(string), AddProperty(Property), RemoveProperty(string), RemoveProperty(Property)

Examples

To check whether a node has a specific property:

// To check whether a node has a specific property first get that node, and then use
// the HasProperty function to check whether the node has that property.
public void Execute(PluginCommandParameter parameter)
{
// Get the node for which you want to check whether it has a specific property.
var rootPage = studio.Project.GetProjectItem("Screens/Screen/RootPage");
// Check whether the RootPage node has the Background Brush property.
bool hasProperty = rootPage.HasProperty(Properties.Node2DBackgroundBrush);
// If the RootPage node does not have the Background Brush property, add it.
if (!hasProperty)
{
rootPage.AddProperty(Properties.Node2DBackgroundBrush);
}
}
void RegisterThumbnailUser ( object  user,
uint  width,
uint  height,
bool  showChildren,
bool  showFullScreen,
Node  contextNode 
)

Registers a user for the thumbnail images for a project item.

Registering allows you to retrieve thumbnail images in the background before Kanzi sets off the ThumbnailChanged event. After registering, the calls to the GetThumbnail retrieve the cached thumbnail image faster than if you do not register. You must deregister using the DeregisterThumbnailUser function when you are not using the thumbnail images anymore.

Parameters
userThe user.
widthThe width of the thumbnail image.
heightThe height of the thumbnail image.
showChildrenIf set to true [show children].
showFullScreenIf set to true [show full screen].
contextNodeThe context node for resources, such as states, that require a node to display themselves in.
See also
GetThumbnail(int, int, bool, bool, Node), DeregisterThumbnailUser
void RemoveProperty ( string  propertyName)

Removes a property from an item.

Parameters
propertyNameThe name of the property to remove.
See also
AddProperty(string), AddProperty(Property)

Examples

To remove a property from a node:

// To remove a property from a node first get that node, and then use the RemoveProperty function to remove the property.
public void Execute(PluginCommandParameter parameter)
{
// Get the node from which you want to remove a property.
var rootPage = studio.Project.GetProjectItem("Screens/Screen/RootPage");
// Remove the Background Brush property from the "RootPage" node you got in the previous line.
rootPage.RemoveProperty(Properties.Node2DBackgroundBrush);
}
void UpdateValidity ( )

Recalculates the validity the item.

This can be called if there has happened an external change that affects the validity but has not triggered change in the item itself. This situation can arise e.g. when implementing EditTimeComponentPlugin that returns problem descriptions based on the state of other nodes than the current one.

Property Documentation

IEnumerable<ProjectItem> Children
get

Gets all child items of a project item.

The child items of the selected item.

See also
GetChild(string), GetChild<T>(string)

Examples

To get all child nodes of a node:

public void Execute(PluginCommandParameter parameter)
{
// Get all child nodes of the RootPage node.
var rootPage = studio.Project.GetProjectItem("Screens/Screen/RootPage").Children;
// Print the name of each child node of the RootPage node to the Kanzi Studio Log window.
foreach (var node in rootPage)
{
studio.Log(node.Name);
}
}

To get all resources from a library:

public void Execute(PluginCommandParameter parameter)
{
// Get all images from the Images directory.
var imagesDirectory = studio.Project.ImageDirectory.Children;
// Print the name of all images in the Images directory to the Kanzi Studio Log window.
foreach (var resource in imagesDirectory)
{
studio.Log(resource.Name);
}
}
string KzbUrl
get

Gets the .kzb URL of a project item.

The .kzb URL gives you the exact location of a project item. For example, you can use the .kzb URL to access a node or a resource in a JavaScript script in your Kanzi application.

The .kzb URL of the project item.

Examples

To get the .kzb URL of a node:

public void Execute(PluginCommandParameter parameter)
{
// Get the node whose type you want to get.
var rootNode = studio.Project.GetProjectItem("Screens/Screen/RootPage");
// Print the .kzb URL of the node to the Kanzi Studio Log window.
studio.Log(rootNode.KzbUrl);
}

To get the .kzb URL of a resource:

public void Execute(PluginCommandParameter parameter)
{
// Get the resource whose type you want to get.
var texturesLibrary = studio.Project.TextureLibrary;
var defaultTexture = texturesLibrary.GetItemByName("Default Texture");
// Print the .kzb URL of the resource to the Kanzi Studio Log window.
studio.Log(defaultTexture.KzbUrl);
}
string Name
getset

Gets and sets the name of a project item.

This is the same value as the value of the Name property. The name must be unique among children of the same parent.

The name of the project item.

Examples

To get the name of a node:

public void Execute(PluginCommandParameter parameter)
{
// Get the node whose name you want to get.
var rootNode = studio.Project.GetProjectItem("Screens/Screen/RootPage");
// Print the name of the node to the Kanzi Studio Log window. In this example it prints "RootPage".
studio.Log(rootNode.Name);
}

To get the name of a resource:

public void Execute(PluginCommandParameter parameter)
{
// Get the resource whose name you want to get.
var texturesLibrary = studio.Project.TextureLibrary;
var defaultTexture = texturesLibrary.GetItemByName("Default Texture");
// Print the name of the resource to the Kanzi Studio Log window. In this example it prints "Default Texture".
studio.Log(defaultTexture.Name);
}

Gets the project in which this item is located.

string TypeDisplayName
get

Gets the type of a project item.

The type of the project item.

Examples

To get the type of a node:

public void Execute(PluginCommandParameter parameter)
{
// Get the node whose type you want to get.
var rootNode = studio.Project.GetProjectItem("Screens/Screen/RootPage");
// Print the type of the node to the Kanzi Studio Log window. In this example it prints "Page".
studio.Log(rootNode.TypeDisplayName);
}

To get the type of a resource:

public void Execute(PluginCommandParameter parameter)
{
// Get the resource whose type you want to get.
var texturesLibrary = studio.Project.TextureLibrary;
var defaultTexture = texturesLibrary.GetItemByName("Default Texture");
// Print the type of the resource to the Kanzi Studio Log window. In this example it prints "Single Texture".
studio.Log(defaultTexture.TypeDisplayName);
}