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.