- Oct 14, 2013
- 184
- 0
- 0
Hi ,
Im unable to bind long list selector in my windows phone 8 application.
FOllowing is the code, im beginner .please have a look on the following code
Markup :
phone
honeApplicationPage.Resources>
<DataTemplate x:Key="itemNewsPaper">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name, Mode=OneWay}" Width="200px"></TextBlock>
</StackPanel>
</DataTemplate>
</phone
honeApplicationPage.Resources>
<phone:LongListSelector x:Name="lstNewspapers" LayoutMode="List" IsGroupingEnabled="False"
ItemTemplate="{StaticResource itemNewsPaper}">
</phone:LongListSelector>
Im unable to bind long list selector in my windows phone 8 application.
FOllowing is the code, im beginner .please have a look on the following code
Code:
public partial class MainPage : PhoneApplicationPage
{
List<Newspaper> news = new List<Newspaper>();
public class ViewModel {
public ObservableCollection<Newspaper> news = new ObservableCollection<Newspaper>();
public ViewModel() {
news.Add(new Newspaper() { Name = "Tribune" });
}
}
// Constructor
public MainPage()
{
InitializeComponent();
//var tmp = new Newspaper();
//tmp.Name = "tribune";
//news.Add(tmp);
//tmp = new Newspaper();
//tmp.Name = "tribune";
//news.Add(tmp);
//tmp = new Newspaper();
//tmp.Name = "The Nation";
//news.Add(tmp);
lstNewspapers.DataContext = new ViewModel().news;
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
Code:
public class Newspaper :INotifyPropertyChanged
{
private string name;
public string Name
{
get { return name; }
set { name = value;
OnPropoertyChanged("Name");
}
}
public void OnPropoertyChanged(string propName) {
if (this.PropertyChanged!=null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
Markup :
phone

<DataTemplate x:Key="itemNewsPaper">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name, Mode=OneWay}" Width="200px"></TextBlock>
</StackPanel>
</DataTemplate>
</phone

<phone:LongListSelector x:Name="lstNewspapers" LayoutMode="List" IsGroupingEnabled="False"
ItemTemplate="{StaticResource itemNewsPaper}">
</phone:LongListSelector>