Benim xaml'ımı viewmodel'imle bağlamak için alamıyorum. Bir resm hakkında veri tutan bir INotifyPropertyChanged sınıfının bir GözlemlenebilirKolumu benim viewModel var. İşte benim Recepie sınıfım:
namespace WP7SQLiteClient.Model
{
public class MainViewModelItem : INotifyPropertyChanged
{
string _title, _subTitle, _imageUriPath;
string title
{
get
{
return _title;
}
set
{
_title = value;
NotifyPropertyChanged("title");
}
}
string subTitle
{
get
{
return _subTitle;
}
set
{
_subTitle = value;
NotifyPropertyChanged("subTitle");
}
}
string imageUriPath
{
get
{
return _imageUriPath;
}
set
{
_imageUriPath = value;
NotifyPropertyChanged("imageUriPath");
}
}
public MainViewModelItem(string title, string subtitle, string imageuripath)
{
this.title = title;
this.subTitle = subtitle;
this.imageUriPath = imageuripath;
}
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
}
Ve resminin listesini tutan ViewModel'im:
namespace WP7SQLiteClient.ViewModel
{
public class PanoramaViewModel : INotifyPropertyChanged
{
public ObservableCollection _recepiesList;
public ObservableCollection recepiesList
{
get
{
return _recepiesList;
}
set
{
_recepiesList = value;
NotifyPropertyChanged("recepiesList");
}
}
public PanoramaViewModel()
{
this.recepiesList = new ObservableCollection();
}
public bool IsDataLoaded
{
get;
private set;
}
public void LoadData()
{
this.recepiesList.Add(new MainViewModelItem("Classics", "", ""));
this.recepiesList.Add(new MainViewModelItem("Perfect Pasta", "", ""));
this.recepiesList.Add(new MainViewModelItem("Favorites", "", ""));
this.recepiesList.Add(new MainViewModelItem("Snacks & Antipasti", "", ""));
this.recepiesList.Add(new MainViewModelItem("Desserts", "", ""));
this.recepiesList.Add(new MainViewModelItem("3 minutes recipes", "", ""));
this.IsDataLoaded = true;
}
private string _sampleProperty = "Sample Runtime Property Value";
///
/// Sample ViewModel property; this property is used in the view to display its value using a Binding
///
///
public string SampleProperty
{
get
{
return _sampleProperty;
}
set
{
if (value != _sampleProperty)
{
_sampleProperty = value;
NotifyPropertyChanged("SampleProperty");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
}
MainPage.xaml (projenin kökünde yer alan viewModel, ViewModel klasöründedir ve Model, Model klasöründedir), liste kutumun şu şekilde bildirilmiş halidir:
Şablon App.xaml'de bulunur ve kesin olarak doğrudur. {Binding title}
gibi şeyler kullanır
MainPage.cs'de görünüm modelini kullanarak sayfayı bağlamaya çalışıyorum:
public static PanoramaViewModel viewModel = null;
public static PanoramaViewModel ViewModel
{
get
{
//Delay creation of the view model until necessary
if (viewModel == null)
viewModel = new PanoramaViewModel();
return viewModel;
}
}
public MainPage()
{
InitializeComponent();
ViewModel.LoadData();
DataContext = ViewModel;
}
Ama işe yaramıyor ya da hata ayıklayıcı bir hata yaratıyor. Viewmodel'i xaml ile doğru şekilde nasıl bağlarım?
UPDATE my template looks like this :
<!-- for recent recepies-->
2 GÜNCELLEME
liste kutusu kodumu değiştirdim:
Hiçbir şablon ile [proje_adı] .Model.MainViewModelItem
listesini alırım, bu yüzden şablonla ilgili bir sorun olduğunu düşünüyorum .. Neyi yanlış yapıyorum?