ConstraintCollection.RemoveAt(Int32) 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从集合中的指定索引处删除 Constraint 对象。
public:
 void RemoveAt(int index);public void RemoveAt (int index);member this.RemoveAt : int -> unitPublic Sub RemoveAt (index As Integer)参数
- index
- Int32
要移除的 Constraint 的索引。
例外
该集合在此索引位置无约束。
示例
以下示例将 IndexOf 方法与 方法一起使用, RemoveAt 以从 ConstraintCollection中删除约束。
private void RemoveConstraint(ConstraintCollection constraints,
    Constraint constraint)
{
    try
    {
        if(constraints.Contains(constraint.ConstraintName))
        {
            if(constraints.CanRemove(constraint))
            {
                constraints.RemoveAt(constraints.IndexOf(
                    constraint.ConstraintName));
            }
        }
    }
    catch(Exception e)
    {
        // Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.",
            e.GetType());
    }
}
Private Sub RemoveConstraint _
    (constraints As ConstraintCollection, constraint As Constraint)
    Try
        If constraints.Contains(constraint.ConstraintName) Then
            If constraints.CanRemove(constraint) Then
                constraints.RemoveAt _
                    (constraints.IndexOf(constraint.ConstraintName))
            End If
        End If
    Catch e As Exception
        ' Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.", _
            e.GetType().ToString())
    End Try
End Sub
注解
方法 IndexOf 返回特定 Constraint的索引。
在使用 RemoveAt 方法之前,可以使用 Contains 方法确定集合是否包含目标 Constraint,并使用 CanRemove 方法确定是否 Constraint 可以删除 。
CollectionChanged如果成功删除约束,则会发生 该事件。