Export (0) Print
Expand All

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()
You cannot use methods in XAML.

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);
}

For the complete example, see StatusBar Sample.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Community Additions

ADD
Show:
© 2014 Microsoft