0

I created a button and wrote its behaviour to clear the scatter view, but it didnt work:

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);              
        }

Before this, I thought to reset the application by this code which didnt work either: (I added using System.Diagnostics; )

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

the xaml:

<s:SurfaceButton  Content="Clear" Name="Button1" Click="Button1_Click" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>

can you tell me what i miss, thanks

sgizm
  • 17
  • 9
  • Your question title is "how to clear all the items...", but your code suggests that you actually mean to remove only the particular ScatterViewItem that contains the Button from the ScatterView. Please be more precise about what you want to achieve. It would also be interesting to see the XAML where the Button is declared. I'm pretty sure that all the VisualTree stuff isn't really needed. – Clemens Feb 11 '13 at 10:16
  • Ya that's right. this code doesn't function what i want. Maybe it is a better idea to reset the application. But it didn't work either. I am adding the code now. – sgizm Feb 11 '13 at 10:25

1 Answers1

0

You can simply give the ScatterView a name

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

and then access it from code behind:

private void Button1_Click(object sender, RoutedEventArgs e)
{
    scatterView.Items.Clear();
}
Clemens
  • 123,504
  • 12
  • 155
  • 268