ItemCollection.Clear Methode

Definition

Löscht die Auflistung und gibt die Verweise auf alle Elemente frei, die sich derzeit in der Auflistung befinden.

public:
 virtual void Clear();
public void Clear();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()

Implementiert

Ausnahmen

Der ItemCollection Modus ist im ItemsSource Modus. (Wenn die ItemsSource Eigenschaft festgelegt wird, wird die Items Sammlung schreibgeschützt und fest festgelegt.)

Beispiele

Das folgende Beispiel zeigt, wie Diese Methode verwendet wird. Im Beispiel sbar handelt es sich um ein Steuerelement, bei dem es sich um ein StatusBarItemsControlSteuerelement handelt.

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);
}
Private Sub MakeProgressBar(ByVal sender As Object, ByVal e As RoutedEventArgs)
    sbar.Items.Clear()
    Dim txtb As New TextBlock()
    txtb.Text = "Progress of download."
    sbar.Items.Add(txtb)
    Dim progressbar As New ProgressBar()
    progressbar.Width = 100
    progressbar.Height = 20
    Dim duration As New Duration(TimeSpan.FromSeconds(5))
    Dim doubleanimation As New DoubleAnimation(100.0, duration)
    progressbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation)
    Dim ttprogbar As New ToolTip()
    ttprogbar.Content = "Shows the progress of a download."
    progressbar.ToolTip = (ttprogbar)
    sbar.Items.Add(progressbar)
End Sub

Gilt für:

Weitere Informationen