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 底層集合為唯讀。

適用於