w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Swap an page and put data (several images and links) in my listbox

You are using Local variable instead of a property:

    ObservableCollection<PopularVideos> _popVideos = new

The above line indicates that you are using a local variable, any changes you make to it are gone with it by the end of the method. You probably wanted to use a property of your class, but didn't.

You should:

  1. Use a property of your class.

  2. Have it be public (naming convention also suggests you call it PopVideos).

  3. Have the binding in your Xaml be correctly defined, as well as the DataContext.

  4. Keep the same instance of the Binded property, doing something like PopVideos = new after the constructor will result in the breaking of the binding.

Code example for a possible solution:

Since some of your code is missing, a simple example of how it should be:


public class MyDataContextClass{
     public ObservableCollection<PopularVideo> PopVideos;

     public MyDataContextClass(){
          PopVideos = new ObservableCollection<PopularVideo>();
     private void DownLoadCompleted(object sender,
HtmlDocumentLoadCompleted e){
         // Add to pop Videos.


It should have it's DataContext set to the relevant instance of MyDataContextClass, one way of doing it:

public class MyXamlViewClass : UserControl{ // could be a
window, or whatever you are using.
    public MyXamlViewClass(MyDataContextClass vm){
        DataContext = vm;
        InitializeComponent();//If I remember the method name correctly


Make sure you bind to your ObservableCollection Properly:

<ListBox Name="listBoxPopular" ItemsSource="{Binding
PopularVideos Mode=OneWay}">

Edit (due to comment):

This is how it should look (different name):

.Xaml &

Replace your relevant code with this one (make sure you change it properly):

MainPage.Xaml.cs : PasteBin

MainPage.Xaml : PasteBin

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.