Try to do it this way :
First, make your ProductListViewModel
implements INotifyPropertyChanged
.
Second, make P
a property instead of field/member, because data-binding only works with public properties. And raise property changed notification properly :
private MobileServiceCollection<Product, Product> _p;
public MobileServiceCollection<Product, Product> P
{
get { return _p; }
set
{
_p = value;
NotifyPropertyChanged("P");
}
}
Third, set DataContext of your view properly. Data-binding resolve path relative to view's current DataContext :
ProductListViewModel plvm = new ProductListViewModel();
public ProductList()
{
InitializeComponent();
this.DataContext = plvm;
}
Forth, set ItemsSource
binding path to P
property of DataContext/ProductListViewModel :
<ListBox x:Name="ListOfProducts" ItemsSource="{Binding P}">