IXRApplication::CreateObject(Object) (Windows Embedded CE 6.0)
1/6/2010
This helper template method creates a new object outside of the element tree. This element can be later added to an existing element tree by adding it either to a collection or as the property value of a UI object.
Syntax
template<typename XRObj>
HRESULT CreateObject(
XRObj** ppObject
)
Parameters
- ppObject
[out] Pointer to a new Silverlight object (derived from IXRDependencyObject) that implements the specific interface required for the object that you created.
Return Value
Returns an HRESULT that indicates success or failure.
Remarks
To use a specific interface pointer type, you can use this helper template overload method. When you supply a derived type, this version automatically supplies a type-safe method that implicitly converts the returned type from a generic interface so that you do not have to explicitly call QueryInterface to convert the generic interface into the required object type. For more information, see Type-Safety in Silverlight for Windows Embedded.
You can use this method to create UI resources, such as controls, visual elements, and behaviors, directly in C++ code. This can serve as an alternative to creating UI resources by loading XAML markup into a visual tree for your application.
You can also use this method to create additional UI resources in C++ code that you want to add to a visual tree that was created by parsing and loading XAML markup.
Adding the New Object to the Visual Tree
After you create an object by using this method, you must insert it into the appropriate location in the visual tree, to display that object on the GUI window and fully integrate with Silverlight for Windows Embedded run-time functionality.
Some kinds of objects must be inserted into object collections that exist in the visual tree. You can obtain a pointer to any object collection and insert an item by calling its inherited method IXRCollection<In_T, Out_T>::Add or IXRCollection<In_T, Out_T>::Insert. The documentation for each collection object indicates how to obtain a pointer to it. For more information, see Classes for Collection Management.
Other kinds of objects must be set as the value of a property that belongs to an object. The object should already exist in the visual tree. After you obtain a pointer to the particular object by calling IXRFrameworkElement::FindName, you can call the Set* method on that object to set an object as the value of the specific property. For example, to set a new brush object as the background of a panel object, you would find that panel object in the visual tree, and then call IXRPanel::SetBackground.
If you are creating a UI element to be displayed on the GUI window, you must add it to the IXRUIElementCollection that belongs to the panel object that covers the window. Any UI element that inherits from IXRFrameworkElement can be added to this UI element collection. This includes IXRUserControl, IXRContentControl, IXRTextBox, IXRItemsControl, IXRImage, and so on. To obtain a pointer to this collection, call IXRPanel::GetChildren.
To add this object to a collection, you can find a collection in the object tree, and then call IXRCollection<In_T, Out_T>::Add or IXRCollection<In_T, Out_T>::Insert.
To generate a separate visual host for this object, you can call IXRApplication::CreateHostFromElementTree.
.NET Framework Equivalent
None.
Requirements
Windows Embedded CE | Windows Embedded CE 6.0 R3 |
See Also
Reference
IXRApplication::CreateObject
IXRApplication