Export (0) Print
Expand All

How to: Remove an Element by Using an Index

This example shows how to remove a Button element by using its index number and the MouseLeftButtonDown event handler.

The following Extensible Application Markup Language (XAML) example creates a TabControl. When the user clicks the Remove Control tab, a MouseLeftButtonDown event handler, RemoveButton, which is in thecode-behind file, removes the control at an index of zero (0).


<TabItem MouseLeftButtonUp="RemoveButton">
<TabItem.Header>Remove Control</TabItem.Header>


void RemoveButton(object sender, MouseButtonEventArgs e)
    if ((sp1.Children.IndexOf(btn) >= 0) || (sp1.Children.IndexOf(btn1) >= 0) || (sp1.Children.IndexOf(btn2) >= 0) || (sp1.Children.IndexOf(btn3) >= 0))

<TabItem MouseLeftButtonUp="ClearButtons">
<TabItem.Header>Clear Controls</TabItem.Header>

Sub RemoveButton(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    If (sp1.Children.IndexOf(btn) >= 0) Or (sp1.Children.IndexOf(btn1) >= 0) Or (sp1.Children.IndexOf(btn2) >= 0) Or (sp1.Children.IndexOf(btn3) >= 0) Then
    End If
End Sub

For the complete sample, see Using Elements Sample.

See Also

Community Additions

© 2015 Microsoft