Click here to Skip to main content
15,893,923 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Below is the code page:
public partial class DataBinding : UserControl<br />    {<br />        public DataBinding()<br />        {<br />            InitializeComponent();<br /><br />            List<PlaylistItem> lstPLI = new List<PlaylistItem>();<br />            for (int i = 0; i < 3; i++)<br />            {<br />                lstPLI.Add(new PlaylistItem("Name" + i.ToString(), "Path" + i.ToString()));<br /><br />            }<br />            lstPlayList.ItemsSource = lstPLI;<br />        }<br />    }<br /><br />    public class PlaylistItem<br />    {<br />        public string FileName;<br />        public string FilePath;<br /><br />        public PlaylistItem()<br />        {<br /><br />        }<br />        public PlaylistItem(string filename,string filepath)<br />        {<br />            FileName = filename;<br />            FilePath = filepath;<br />        }<br />    }



And here is the xaml page:
<UserControl x:Class="FirstSilverLight.DataBinding"<br />    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <br />    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" <br />    Width="400" Height="300"><br />    <Grid x:Name="LayoutRoot" Background="White"><br />        <ListBox x:Name="lstPlayList"><br />            <ListBox.ItemTemplate><br />                <DataTemplate><br />                    <StackPanel Orientation="Horizontal"><br />                        <TextBlock Text="{Binding FileName}"></TextBlock><br />                        <TextBlock Text="{Binding FilePath}"></TextBlock><br />                    </StackPanel><br />                </DataTemplate><br />            </ListBox.ItemTemplate><br />        </ListBox><br />    </Grid><br /></UserControl>


The Listbox doesnot show any items in it when I run this, though Listbox items.count is 3 when i debug this. Any idea what the problem is?

Posted

1 solution

Make the strings properties instead of fields:
public string FileName { get; set; }<br />    public string FilePath { get; set; }


 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900