XamlDirect.RemoveFromCollection(IXamlDirectObject, IXamlDirectObject) 方法

定义

尝试从指定的 IXamlDirectObject 集合中删除值。

public:
 virtual bool RemoveFromCollection(IXamlDirectObject ^ xamlDirectObject, IXamlDirectObject ^ value) = RemoveFromCollection;
bool RemoveFromCollection(IXamlDirectObject const& xamlDirectObject, IXamlDirectObject const& value);
public bool RemoveFromCollection(IXamlDirectObject xamlDirectObject, IXamlDirectObject value);
function removeFromCollection(xamlDirectObject, value)
Public Function RemoveFromCollection (xamlDirectObject As IXamlDirectObject, value As IXamlDirectObject) As Boolean

参数

xamlDirectObject
IXamlDirectObject

引用特定的 IXamlDirectObject 集合。

value
IXamlDirectObject

引用要从集合中删除的 IXamlDirectObject 值。

返回

Boolean

bool

如果存在值,则为 true。 如果值不存在,则为 false

示例

以下示例演示如何使用 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);

xd.RemoveFromCollection(childrenCollection, button); // Should return true
xd.RemoveFromCollection(childrenCollection, button); // Should return false
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);

xd->RemoveFromCollection(childrenCollection, button); // Should return true
xd->RemoveFromCollection(childrenCollection, button); // Should return false

适用于

另请参阅