ListBox and Listview problem
Posted
by Anu
on Stack Overflow
See other posts from Stack Overflow
or by Anu
Published on 2010-04-17T05:20:22Z
Indexed on
2010/04/17
5:23 UTC
Read the original article
Hit count: 301
Hi, I have listbox in my applcation and corresponding coding.. XAML:
<DataTemplate x:Key="menuItemTemplate">
<WrapPanel>
<TextBlock Text="{Binding Path = Menu}" />
</WrapPanel>
</DataTemplate>
<ListBox x:Name="menubox" ItemsSource="{Binding}" ItemTemplate="{StaticResource menuItemTemplate}" Margin="0,5,0,0">
.CS :
public void Add(string[] menu)
{
ItemList items = ItemList.Load(menu);
DataContext = items;
}
It works fine.Later i add Listview for another purpose and i coded like the same way of listbox XAML:
<DataTemplate x:Key="ListItemTemplate">
<WrapPanel>
<TextBlock Text="{Binding Path = Title}" />
</WrapPanel>
</DataTemplate>
<ListView ItemsSource="{Binding}" ItemTemplate="{StaticResource ListItemTemplate}" Name="listView1" />
.cs coding:
public void SetTree(string Title,int BoxNo )
{
TreeList items1 = TreeList.Load(Title,BoxNo);
DataContext = items1;
}
After adding Listview,what happended this ListView show data,but Listbox didnot show anything.When i click the listbox it perfectly executing the clicking event of listbox.Only problem it doesnot display the text.What can i do for that. Here i added corresponding list class pls see tht.
namespace Tabcontrol
{
public class TreeList : Collection<TreeItems>
{
public int size;
public TreeList()
{
size = 0;
}
public int Count
{ get { return size; }
}
public static TreeList Load(string pmenu,int Box)
{
TreeList result = new TreeList();
TreeItems item = TreeItems.Load(pmenu,Box);
result.Add(item);
return result;
}
}
}
The ItemList class also the same thing, only variable names are getting differred.
© Stack Overflow or respective owner