0

I'm creating a windows WPF interface for an XML API of a Music catalog.

So in creating the list of albums, songs, playlists, etc, I created list boxes with columns (with visual studio 'cause I have no experience on windows programming):

<Window x:Class="AmpacheWPF.Programacion"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:AmpacheWPF"
    mc:Ignorable="d"
    Title="Programacion" Height="917.833" Width="1206.666">
<Grid>
    <ComboBox x:Name="comboBox" HorizontalAlignment="Left" Margin="26,39,0,0" VerticalAlignment="Top" Width="120" SelectionChanged="comboBox_SelectionChanged"/>
    <ListView x:Name="albums" HorizontalAlignment="Left" Height="146" Margin="26,99,0,0" VerticalAlignment="Top" Width="549" SelectionChanged="albums_SelectionChanged">

        <ListView.View >
            <GridView AllowsColumnReorder="False">
                <GridView.ColumnHeaderContextMenu>
                    <ContextMenu/>
                </GridView.ColumnHeaderContextMenu>
                <GridViewColumn Header="Album"
                                DisplayMemberBinding="{Binding Album}" Width="120"/>
                <GridViewColumn Header="Artist"
                                DisplayMemberBinding="{Binding Artist}"/>
                <GridViewColumn Header="Year"
                                DisplayMemberBinding="{Binding Year}"/>
            </GridView>
        </ListView.View>
    </ListView>
    <Label x:Name="label" Content="Label" HorizontalAlignment="Left" Margin="160,54,0,0" VerticalAlignment="Top"/>
    <ListView x:Name="Songs" HorizontalAlignment="Left" Height="257" Margin="26,286,0,0" VerticalAlignment="Top" Width="549" SelectionChanged="Songs_SelectionChanged">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="#"
                                DisplayMemberBinding="{Binding Pista}"/>
                <GridViewColumn Header="Cancion"
                                DisplayMemberBinding="{Binding Titulo}"/>
                <GridViewColumn Header="Compositor"
                                DisplayMemberBinding="{Binding Compositor}"/>
                <GridViewColumn Header="Artista"
                                DisplayMemberBinding="{Binding Artist}"/>
                <GridViewColumn Header="Tiempo"
                                DisplayMemberBinding="{Binding Tiempo}"/>
                <GridViewColumn Header="Genero"
                                DisplayMemberBinding="{Binding Genero}"/>
            </GridView>
        </ListView.View>
    </ListView>

</Grid>

It has Columns (Album, Artist, Year) All the info is auto-filled with the XML API of my music server.

I have a combo box with Genres (Latin, Salsa, etc)

Every time I click a genre it loads the info in the ListView albums, and when I click an album it fills the ListView songs.

What I'm trying to do with no success is to fix the columns' size (that is the only thing I can do with "width") and want the columns to expand vertically when the text doesn't fit on the column width (like Microsoft excel does) (so I have a 2 or 3 line rows) but please tell me where to put it on the code because really I have no experience programming on windows.

Here is some example of my code in case it helps:

public Programacion()
    {
        InitializeComponent();
        serverurl = Loginwindow.serverurl;
        string ampuser = Loginwindow.ampuser;
        token = Loginwindow.token;

        //obteniendo lista de tags
        string tagurl = "http://" + serverurl + "/server/xml.server.php?action=tags&auth=" + token;
        string[] tagarray = { tagurl, "1", "tag", "name", "albums" };//Creando array con datos a utilizar
        tagsinfo = xmlcs2.Xmlparser(tagarray);//Llamando afuncion que lee XML

        //Obteniendo total de espacios musicales contando el array
        totalgenres = tagsinfo.GetUpperBound(0);

        //Lennado ComboBox1
        int g = Programacion.totalgenres;
        for (int y = 0; y < g; y++)
        {
            comboBox.Items.Add(tagsinfo[y][1]); //
        }

    }

    private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        int index = comboBox.SelectedIndex;
        id = tagsinfo[index][0];
        string totalalbums = tagsinfo[index][2];


        //obteniendo lista de albums
        string tagurl = "http://" + serverurl + "/server/xml.server.php?action=tag_albums&auth=" + token + "&filter=" + id;
        string[] tagarray = { tagurl, totalalbums, "album", "name", "tracks", "artist", "year" };//Creando array con datos a utilizar
        albumsinfo = xmlcs2.Xmlparser(tagarray);//Llamando afuncion que lee XML

        //ordenando alfabeticamente
        Sort(albumsinfo, 1);

        //Lennado ListView Albums
        albums.ItemsSource = null;
        int g = Convert.ToInt32(totalalbums);

        List<Albumlist> items = new List<Albumlist>();
        for (int y = 0; y < g; y++)
        {

            if (albumsinfo[y][4] == "0")
            {

                items.Add(new Albumlist() { Album = albumsinfo[y][1], Artist = albumsinfo[y][3], Year = "" });


            }
            else
            {
                items.Add(new Albumlist() { Album = albumsinfo[y][1], Artist = albumsinfo[y][3], Year = albumsinfo[y][4], Id = albumsinfo[y][0] });



            }



        }
        albums.ItemsSource = items;


    }

Thanks in advance for your help.

Stewbob
  • 16,759
  • 9
  • 63
  • 107
  • Possible duplicate of [TextBlock text wrapping in GridViewColumn.CellTemplate not working](http://stackoverflow.com/questions/11101360/textblock-text-wrapping-in-gridviewcolumn-celltemplate-not-working) – Stewbob May 02 '17 at 17:42

1 Answers1

0

It looks like what you need to do is change out the DisplayMemberBinding in your GridView for CellTemplate as per this answer, which will allow you to customize the presenter object into a custom TextBlock with wrapping (this will then also do the right thing with regards to letting the grid layout know it needs more space).

You might not get Excel-behavior right away, and you may need to play around with the other TextBlock settings to get it to work exactly how you want.

Community
  • 1
  • 1
J Alber
  • 39
  • 4
  • Thank you very much, ihave seen that post but with your explanation now im understand what should I change, i will post the finall code for someone who needs it on the future – Manuel Gonzalez May 03 '17 at 15:08