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 as IEditableCollectionView; 

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 基礎集合是唯讀的,則為 。

適用於