共用方式為


XamlDirect.AddToCollection(IXamlDirectObject, IXamlDirectObject) 方法

定義

將值加入至指定的 IXamlDirectObject 集合。

public:
 virtual void AddToCollection(IXamlDirectObject ^ xamlDirectObject, IXamlDirectObject ^ value) = AddToCollection;
void AddToCollection(IXamlDirectObject const& xamlDirectObject, IXamlDirectObject const& value);
public void AddToCollection(IXamlDirectObject xamlDirectObject, IXamlDirectObject value);
function addToCollection(xamlDirectObject, value)
Public Sub AddToCollection (xamlDirectObject As IXamlDirectObject, value As IXamlDirectObject)

參數

xamlDirectObject
IXamlDirectObject

參考特定的 IXamlDirectObject 集合。

value
IXamlDirectObject

參考要加入至集合的 IXamlDirectObject 值。

範例

下列範例示範如何使用 XamlDirect API 將值新增至集合。

XamlDirect xd = XamlDirect.GetDefault();

IXamlDirectObject relativePanel = xd.CreateInstance(XamlTypeIndex.RelativePanel);

IXamlDirectObject childrenCollection = xd.GetXamlDirectObjectProperty(relativePanel, XamlPropertyIndex.Panel_Children);

IXamlDirectObject button = xd.CreateInstance(XamlTypeIndex.Button);
xd.AddToCollection(childrenCollection, button);
XamlDirect^ xd = XamlDirect::GetDefault();

IXamlDirectObject^ relativePanel = xd->CreateInstance(XamlTypeIndex::RelativePanel);

IXamlDirectObject^ childrenCollection = xd->GetXamlDirectObjectProperty(relativePanel, XamlPropertyIndex::Panel_Children);

IXamlDirectObject^ button = xd->CreateInstance(XamlTypeIndex::Button);
xd->AddToCollection(childrenCollection, button);

備註

IXamlDirectObject 是 Xaml 內建物件實例的最低控制碼。 因此,要加入至集合的集合和值都是 IXamlDirectObject類型。

適用於

另請參閱