Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Clear Method

ItemCollection.Clear Method

Clears the collection and releases the references on all items currently in the collection.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

public void Clear()

Implements

IList.Clear()

ExceptionCondition
InvalidOperationException

The ItemCollection is in ItemsSource mode. (When the ItemsSource property is set, the Items collection will be made read-only and fixed-size.)

The following example shows how to use this method. In the example, sbar is a StatusBar control, which is an ItemsControl.

private void MakeProgressBar(object sender, RoutedEventArgs e)
{
    sbar.Items.Clear();
    TextBlock txtb = new TextBlock();
    txtb.Text = "Progress of download.";
    sbar.Items.Add(txtb);
    ProgressBar progressbar = new ProgressBar();
    progressbar.Width = 100;
    progressbar.Height = 20;
    Duration duration = new Duration(TimeSpan.FromSeconds(5));
    DoubleAnimation doubleanimation =
                               new DoubleAnimation(100.0, duration);
    progressbar.BeginAnimation(ProgressBar.ValueProperty,
                               doubleanimation);
    ToolTip ttprogbar = new ToolTip();
    ttprogbar.Content = "Shows the progress of a download.";
    progressbar.ToolTip = (ttprogbar);
    sbar.Items.Add(progressbar);
}

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft