C# 在ListView中添加内容时垂直展开列
我正在为音乐目录的XML API创建一个windows WPF接口 因此,在创建专辑、歌曲、播放列表等列表时,我创建了带有列的列表框(使用visual studio,因为我没有windows编程经验):C# 在ListView中添加内容时垂直展开列,c#,wpf,listview,visual-studio-2015,C#,Wpf,Listview,Visual Studio 2015,我正在为音乐目录的XML API创建一个windows WPF接口 因此,在创建专辑、歌曲、播放列表等列表时,我创建了带有列的列表框(使用visual studio,因为我没有windows编程经验): 它有专栏(专辑、艺术家、年份) 所有信息都是用我的音乐服务器的XMLAPI自动填充的 我有一个组合框,里面有各种类型(拉丁、萨尔萨等) 每次单击某个流派时,它都会加载ListView相册中的信息,当我单击某个相册时,它会填充ListView歌曲 我试图做但没有成功的事情是固定列的大小(这是
它有专栏(专辑、艺术家、年份)
所有信息都是用我的音乐服务器的XMLAPI自动填充的
我有一个组合框,里面有各种类型(拉丁、萨尔萨等)
每次单击某个流派时,它都会加载ListView相册中的信息,当我单击某个相册时,它会填充ListView歌曲
我试图做但没有成功的事情是固定列的大小(这是我唯一能用“宽度”做的事情),并希望当文本不适合列宽时,列垂直扩展(就像Microsoft excel那样)(因此我有2行或3行)但是请告诉我把它放在代码的什么地方,因为我真的没有在windows上编程的经验
下面是我的一些代码示例,以防有所帮助:
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;
}
publicprogramacion()
{
初始化组件();
serverurl=Loginwindow.serverurl;
字符串ampuser=Loginwindow.ampuser;
token=Loginwindow.token;
//标签清单
string tagurl=“http://”+serverurl+“/server/xml.server.php?action=tags&auth=“+token;
string[]tagarray={tagurl,“1”,“tag”,“name”,“albums”};//Creando数组con datos a utilizar
tagsinfo=xmlcs2.Xmlparser(tagarray);//Llamando afuncion que lee XML
//康坦多音乐总台
totalgenres=tagsinfo.GetUpperBound(0);
//Lennado Combox1
int g=Programacion.totalgenres;
对于(int y=0;y
提前感谢您的帮助。看起来您需要做的是根据更改GridView for CellTemplate中的DisplayMemberBinding,这将允许您将presenter对象自定义为带有包装的自定义文本块(这样也可以让网格布局知道它需要更多的空间)
您可能无法立即获得Excel behavior,您可能需要使用其他文本块设置,以使其完全按照您的意愿工作。非常感谢,我已经看到了该帖子的可能副本,但有了您的解释,我现在明白我应该更改什么了,我将为需要它的人在fu上发布最终代码图雷
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;
}