After you have defined a custom control element, you can use it in your UXML files. To categorize elements, create the class in a namespace. When you define a new namespace, you can define a prefix for the namespace. You must define namespace prefixes as attributes of the root <UXML>
element and replace the full namespace name when scoping elements.
To define a namespace prefix, add a UxmlNamespacePrefix
attribute to your assembly for each namespace prefix. For example:
[assembly: UxmlNamespacePrefix("My.First.Namespace", "first")]
[assembly: UxmlNamespacePrefix("My.Second.Namespace", "second")]
此操作可以在程序集的任何 C# 文件的根级别(在任何命名空间之外)完成。
架构生成系统会执行以下操作:
<UXML>
element in newly created UXML files.xsi:schemaLocation
属性中。To ensure that your text editor recognizes the new element, select Assets > Update UXML Schema to update the schema definition.
To create a new UXML document with the prefix, select Assets > Create > UI Toolkit > UI Document.