Skip to main content
.NET Framework Class Library
UIElementCollectionContains Method

Determines whether a specified element is in the UIElementCollection.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
Syntax
Public Overridable Function Contains ( _
	element As [%$TOPIC/ms603592_en-us_VS_110_2_0_0_0_0%] _
) As [%$TOPIC/ms603592_en-us_VS_110_2_0_0_0_1%]
public virtual [%$TOPIC/ms603592_en-us_VS_110_2_0_1_0_0%] Contains(
	[%$TOPIC/ms603592_en-us_VS_110_2_0_1_0_1%] element
)
public:
virtual [%$TOPIC/ms603592_en-us_VS_110_2_0_2_0_0%] Contains(
	[%$TOPIC/ms603592_en-us_VS_110_2_0_2_0_1%]^ element
)
abstract Contains : 
        element:[%$TOPIC/ms603592_en-us_VS_110_2_0_3_0_0%] -> [%$TOPIC/ms603592_en-us_VS_110_2_0_3_0_1%]  
override Contains : 
        element:[%$TOPIC/ms603592_en-us_VS_110_2_0_3_0_2%] -> [%$TOPIC/ms603592_en-us_VS_110_2_0_3_0_3%]
public function Contains(
	element : [%$TOPIC/ms603592_en-us_VS_110_2_0_4_0_0%]
) : [%$TOPIC/ms603592_en-us_VS_110_2_0_4_0_1%]

Parameters

element
Type: System.WindowsUIElement

The element to find.

Return Value

Type: SystemBoolean
true if the specified UIElement is found in the collection; otherwise, false.
Examples

The following example uses the Contains method to determine if a specific UIElement exists within a UIElementCollection.

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
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();
}
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1