WPF Scatterview项目 - 如何通过单击按钮清除所有项目?

时间:2013-02-11 09:34:06

标签: wpf scatterview

我创建了一个按钮并编写了它的行为以清除散点图,但它没有用:

private void Button1_Click(object sender, RoutedEventArgs e)
        {
            DependencyObject parent = VisualTreeHelper.GetParent(this);
            ScatterViewItem svi = null;
            while (parent as ScatterView == null)
            {
                if (parent is ScatterViewItem)
                    svi = parent as ScatterViewItem;
                parent = VisualTreeHelper.GetParent(parent);
            }

            ((ScatterView)parent).Items.Remove(svi);              
        }

在此之前,我想通过这个代码重置应用程序,它也没有工作:(我添加了使用System.Diagnostics;)

private void Button1_Click(object sender, RoutedEventArgs e)
    {    
       Process.Start(Application.ResourceAssembly.Location);    
       Application.Current.Shutdown();                      
    }

xaml:

<s:SurfaceButton  Content="Clear" Name="Button1" Click="Button1_Click" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
你能告诉我我想念的吗? 感谢

1 个答案:

答案 0 :(得分:0)

您可以简单地为ScatterView命名

<s:ScatterView x:Name="scatterView" ... />

然后从后面的代码访问它:

private void Button1_Click(object sender, RoutedEventArgs e)
{
    scatterView.Items.Clear();
}