IEditableCollectionView.CanRemove Eigenschaft

Definition

Ruft einen Wert ab, der angibt, ob ein Element aus der Auflistung entfernt werden kann.

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

Eigenschaftswert

truewenn ein Element aus der Sammlung entfernt werden kann; andernfalls . false

Beispiele

Im folgenden Beispiel wird überprüft CanRemove , ob ein Element aus der Auflistung entfernt werden kann. Wenn ein Element entfernt werden kann, fordert das Beispiel den Benutzer auf, die Aktion zu bestätigen und aufruft Remove , wenn der Benutzer auf "Ja" klickt. Das gesamte Beispiel finden Sie unter Ändern einer Auflistung mithilfe des IEditableCollectionView-Beispiels.

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

Hinweise

CanRemove ist false , wenn die zugrunde liegende Auflistung schreibgeschützt ist.

Gilt für: