IEditableCollectionView.CanRemove Свойство

Определение

Возвращает значение, указывающее, можно ли удалить элемент из коллекции.

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

Значение свойства

Значение , если элемент можно удалить из коллекции; в противном случае .

Примеры

В следующем примере вызывается CanRemove проверка возможности удаления элемента из коллекции. Если элемент можно удалить, в примере появится запрос на подтверждение действия и вызовы Remove , если пользователь нажимает кнопку "Да". Полный пример см. в разделе "Изменение коллекции с помощью примера IEditableCollectionView".

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

Комментарии

CanRemove Значение , false если базовая коллекция доступна только для чтения.

Применяется к