1

I have a string[] in WPF that is a list of artists. I want to display them as following: Artist A, Artist B, Artist C (this being 3 items in the array). Each of the items needs to be clickable and I need to be able to act on the clicks. This view shall be put into a ListView of songs that is using a GridView (this works already, but currently it only displays System.String[] in the artists-cells).

When the user clicks on an artist, I need to know what song index and what artist-index that was clicked (or what song index and what artist (the string), then I can just use IndexOf() to find the artist-index). Also, I don't want scrollbars to be shown in the cell, so if the array is too long the content should be clipped.

How would I make something like this?

[Edit]

What I have so far is this:

<ListView x:Name="SpotifySongs" Grid.Row="3" Grid.Column="1" BorderThickness="0" ItemContainerStyle="{StaticResource ResourceKey=TrackListRowStyle}"
          >
    <ListView.View>
        <GridView AllowsColumnReorder="False">
            <GridViewColumn Width="25" Header="">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Image Source="{Binding Path=IsStarred, Converter={StaticResource ResourceKey=StarredConverter}}" Height="13" Width="13" Margin="0" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Width="150" Header="Track" DisplayMemberBinding="{Binding Path=Name}"></GridViewColumn>
            <GridViewColumn Width="150" Header="Artist">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <ListView ItemsSource="{Binding Path=Artists}" BorderThickness="0" ScrollViewer.CanContentScroll="False" Background="Transparent">
                            <ListView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal" CanHorizontallyScroll="False" CanVerticallyScroll="False" ClipToBounds="True"
                                                Background="Transparent">
                                    </StackPanel>
                                </ItemsPanelTemplate>
                            </ListView.ItemsPanel>
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType=ListViewItem, AncestorLevel=2}}"
                                               Background="Transparent"
                                               Text="{Binding}"/>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Width="50" Header="Time" DisplayMemberBinding="{Binding Path=Length}"></GridViewColumn>
            <GridViewColumn Width="150" Header="Album" DisplayMemberBinding="{Binding Path=Album}"></GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

The Artist-column beeing the artists. There are 3 problems, the first one is to get a , between the artist-names, the second is to remove the scrollbars and enable clipping if there are two many artists to display within 150px, and the last one (I believe I've solved that one) is the clicking.

Notifications on update isn't important as I keep swapping the source when there is new data (because it's normally all new).

1
  • 3
    You're going to have to narrow this down to a more specific problem. You've almost asked someone to write the whole thing out for you. Commented Feb 27, 2011 at 3:35

1 Answer 1

1

I would use a List object as ListView's DataSource is an ICollection or IList which String[] is not.

    List<String> stringList = new List<string>();

    stringList.Add("Artist 1");
    stringList.Add("Artist 2");
    stringList.Add("Artist 3");
    stringList.Add("Artist 4");

    lsv.ItemsSource = stringList;

XAML

<ListView x:Name="lsv" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.