UIElementCollection.Contains(UIElement) UIElementCollection.Contains(UIElement) UIElementCollection.Contains(UIElement) UIElementCollection.Contains(UIElement) Method

Определение

Определяет, находится ли указанный элемент в UIElementCollection.Determines whether a specified element is in the UIElementCollection.

public:
 virtual bool Contains(System::Windows::UIElement ^ element);
public virtual bool Contains (System.Windows.UIElement element);
abstract member Contains : System.Windows.UIElement -> bool
override this.Contains : System.Windows.UIElement -> bool
Public Overridable Function Contains (element As UIElement) As Boolean

Параметры

element
UIElement UIElement UIElement UIElement

Элемент для поиска.The element to find.

Возвраты

true, если указанный UIElement найден в коллекции; в противном случае — false.true if the specified UIElement is found in the collection; otherwise, false.

Примеры

В следующем примере Contains метод используется для определения существования конкретного UIElement элемента в UIElementCollection.The following example uses the Contains method to determine if a specific UIElement exists within a UIElementCollection.

void ContainsElement(object sender, RoutedEventArgs e)
{
    TextBlock txt1 = new TextBlock();
    sp1.Children.Add(txt1);
    txt1.Text = "This StackPanel contains UIElement btn1: " + sp1.Children.Contains(btn1).ToString();
}
Private Sub ClearButtons(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    sp1.Children.Clear()
    btn = New Button()
    btn.Content = "Click to clear"
    sp1.Children.Add(btn)
    AddHandler btn.Click, AddressOf Me.ClearControls
    btn1 = New Button()
    btn1.Content = "Click to clear"
    sp1.Children.Add(btn1)
    AddHandler btn1.Click, AddressOf Me.ClearControls
    btn2 = New Button()
    btn2.Content = "Click to clear"
    sp1.Children.Add(btn2)
    AddHandler btn2.Click, AddressOf Me.ClearControls
    btn3 = New Button()
    btn3.Content = "Click to clear"
    sp1.Children.Add(btn3)
    AddHandler btn3.Click, AddressOf Me.ClearControls
End Sub

Private Sub ClearControls(ByVal sender As Object, ByVal e As RoutedEventArgs)
    sp1.Children.Clear()
End Sub

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