IEditableCollectionView.CanRemove 속성

정의

컬렉션에서 항목을 제거할 수 있는지 여부를 나타내는 값을 가져옵니다.

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

속성 값

true컬렉션에서 항목을 제거할 수 있으면 이고, 그렇지 않으면 . false

예제

다음 예제에서는 컬렉션에서 항목을 제거할 수 있는지 여부를 확인 하기 위해 호출 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

설명

CanRemovefalse 기본 컬렉션이 읽기 전용인 경우입니다.

적용 대상