Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding listbox with MVVM Windows Phone
    primarykey
    data
    text
    <p>Hi i'm new using MVVM and i'm trying to binding a listbox but it doesn't work. Here's my code</p> <p><strong>Model</strong></p> <pre><code> public class Musicmodel : INotifyPropertyChanged { //variables privadas private String _artista; private Uri _href; private String _informacion; private Double _Dvalue; public String artista { get { return this._artista; } set { this._artista= value; this.RaisePropertyChanged("artista"); } } public Uri href { get { return this._href; } set { this._href = value; this.RaisePropertyChanged("href"); } } public String informacion { get { return this._informacion; } set { this._informacion = value; this.RaisePropertyChanged("informacion"); } } public Double Dvalue { get { return this._Dvalue; } set { this._Dvalue = value; this.RaisePropertyChanged("Dvalue"); } } public event PropertyChangedEventHandler PropertyChanged; private void RaisePropertyChanged(string propertyName) { if (this.PropertyChanged != null) { this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } } </code></pre> <p><strong>ViewModel</strong></p> <pre><code>public class DownloadFileViewModel : INotifyPropertyChanged { private WebClient clienteDownload; private ObservableCollection&lt;Model.Music&gt;_musicSource= new ObservableCollection&lt;Model.Music&gt;(); public ObservableCollection&lt;Model.Music&gt; musicSource { get { return this._musicSource; } set { this._musicSource = value; RaisePropertyChanged("musicSource"); } } private int index = 0; //request para descargar la canción public void request(Model.Musicmodel item) { this.clienteDownload = new WebClient(); this.clienteDownload.DownloadProgressChanged += new DownloadProgressChangedEventHandler(clienteDownload_DownloadProgressChanged); //agregamos el item al music this.musicSource.Add(item); this.clienteDownload.OpenReadAsync(this.musicSource[index].href); } private void clienteDownload_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { this.musicSource[index].Dvalue=(double)e.ProgressPercentage; } public event PropertyChangedEventHandler PropertyChanged; private void RaisePropertyChanged(string propertyName) { if (this.PropertyChanged != null) { this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } } </code></pre> <p><strong>View</strong></p> <pre><code> &lt;ListBox x:Name="list" ItemsSource="{Binding musicSource}"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Vertical"&gt; &lt;TextBlock Text="{Binding artista}"/&gt; &lt;ProgressBar Value="{Binding Dvalue}"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p><strong>Code Behind</strong></p> <pre><code> protected override void OnNavigatedTo(NavigationEventArgs e) { DownloadFileViewModel download = new DownloadFileViewModel(); Model.Music newMusic = new Model.Music() { href = new Uri("http://media1.li.ru/b/4/mp3/2/95366/953662_14Friday_Im_In_Love.mp3", UriKind.Absolute), artista = "the cure" }; download.request(newMusic); this.DataContext = download; base.OnNavigatedTo(e); } </code></pre> <p>I've debuged this and the download works fine and my ObservableCollection fills correctly whithout any problem but when i try to binding my listbox fails. please what do i'm doing wrong? thanks </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload