0
我创建了一个按钮,并写下自己的行为以清除分散的观点,但它没有工作: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);
}
在此之前,我以为可以重设这个代码没有工作的应用程序之一:(我添加使用系统.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"/>
你能告诉我什么,我错过了, 感谢
你的问题的标题是“如何清除所有的项目......”,但你的代码建议你实际上只是从ScatterView中删除包含Button的特定ScatterViewItem。请更准确地说明你想达到的目标。查看声明Button的XAML也会很有趣。我很确定所有VisualTree的东西都不是真的需要。 – Clemens 2013-02-11 10:16:23
Ya没错。此代码不起作用,我想要的。也许这是重置应用程序更好的主意。但它也没有效果。我现在添加代码。 – sgizm 2013-02-11 10:25:51