IEditableCollectionView.CanRemove Tulajdonság

Definíció

Olyan értéket kap, amely jelzi, hogy eltávolítható-e egy elem a gyűjteményből.

public:
 property bool CanRemove { bool get(); };
public bool CanRemove { get; }
member this.CanRemove : bool
Public ReadOnly Property CanRemove As Boolean

Tulajdonság értéke

trueha egy elem eltávolítható a gyűjteményből; egyéb esetben. false

Példák

Az alábbi példa felhívja CanRemove annak ellenőrzésére, hogy eltávolítható-e egy elem a gyűjteményből. Ha el lehet távolítani egy elemet, a példa arra kéri a felhasználót, hogy erősítse meg a műveletet, és hívja meg Remove , ha a felhasználó az Igen gombra kattint. A teljes minta esetében lásd: Gyűjtemények módosítása az IEditableCollectionView minta használatával.

IEditableCollectionView editableCollectionView =
        itemsControl.Items;

if (!editableCollectionView.CanRemove)
{
    _ = MessageBox.Show("You cannot remove items from the list.");
    return;
}

if (MessageBox.Show("Are you sure you want to remove " + item.Description,
                    "Remove Item", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
    editableCollectionView.Remove(itemsControl.SelectedItem);
}
Dim editableCollectionView As IEditableCollectionView = TryCast(itemsControl.Items, IEditableCollectionView)

If Not editableCollectionView.CanRemove Then
    MessageBox.Show("You cannot remove items from the list.")
    Return
End If

If MessageBox.Show("Are you sure you want to remove " & item.Description, "Remove Item", MessageBoxButton.YesNo) = MessageBoxResult.Yes Then
    editableCollectionView.Remove(itemsControl.SelectedItem)
End If

Megjegyzések

CanRemove akkor, false ha az alapul szolgáló gyűjtemény írásvédett.

A következőre érvényes: