ItemCollection.Clear 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
清除集合并释放集合中当前所有项的引用。
public:
virtual void Clear();
public void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()
实现
例外
ItemCollection 处于 ItemsSource 模式。 (当设置 ItemsSource 属性时,Items 集合将是只读的,且具有固定大小。)
示例
以下示例演示如何使用此方法。 在此示例中, sbar
是一个 StatusBar 控件,即一个 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);
}
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