views:

176

answers:

2

Hi,

I have worked through the answer provided here. I have been able to create a list of automatically generated Hyperlink buttons in a ListBox. The goal is that, when a different user is typed into the box and the button is clicked, they old artists are removed (assuming it's a valid username) and replaced with the artists from the new last.fm user. However, now this line does not work:

ArtistsList.Items.Clear();

Is this only for text? If so, does anybody know another way to remove the hyperlink buttons once the Go! button has been clicked again? I'll provide what I believe to be the pertinent page.xaml.cs code if that will help.

            if (uname.Text != String.Empty && uname.Text != "Try Another One!")
            {
                App app = (App)Application.Current;
                app.UserName = uname.Text;
                String getTopArtists = "http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=" + app.UserName + "&api_key=d2d620af554a60f228faed8d502c4936";
                WebClient web = new WebClient();
                WebClient client = new WebClient();
                client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCompleted);
                client.DownloadStringAsync(new Uri(getTopArtists));
            }

This is what the HyperlinkButton looks like in the page.xaml code:

<ListBox FontFamily="Calibri" HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" Height="200" Margin="50,140,50,50" x:Name="ArtistsList" Foreground="Crimson">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <HyperlinkButton Content="{Binding Name}" NavigateUri="{Binding Amazon}" TargetName="_blank" Width="173.5" Foreground="Crimson"></HyperlinkButton>
            </StackPanel>
         </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

I believe this is all of the necessary code to answer the question. If not, I can provide more.

+2  A: 

instead of using ArtistsList.Items.Clear(); just try ArtistsList.ItemsSource=null; ArtistsList.ItemsSource = [newlistsource]. If you do not understand please reply

mrsaif
A: 

mrsaif is right, the list is bound so you shouldn't try to manually clear it, in SL3 it will throw an error attempting to do that, placing null on the itemsource will remove the contents of the list.

Andrew