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 ()
public final void Clear ()
public final function Clear ()
You cannot use methods in XAML.

Exception typeCondition

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();
  Duration duration = new Duration(TimeSpan.FromSeconds(10));
  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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2016 Microsoft