How to update listbox with ObservableCollection data in Win RT

0

I am trying to update listbox form ObservableCollection but don't know what am doing wrong that i always get the exception below. i am new to winRT.

The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

<ListBox x:Name="UserList" HorizontalContentAlignment="Stretch" Margin="12,41,12,12">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid Margin="10">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="20" />
                        <ColumnDefinition Width="150" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding Title}" Margin="3" Grid.Column="0" />
                    <TextBlock Text="{Binding Description}" Margin="3" Grid.Column="1" />
                    <TextBlock Text="{Binding Title}" Margin="3" Grid.Column="2" />
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
      </ListBox>  

C# code.

protected  override void OnViewModelCollectionChanged(object sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {

         this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
       {
           UserList.ItemsSource = Items;

       }).AsTask().Wait();


    }
c#
listview
listbox
windows-runtime
asked on Stack Overflow Jul 15, 2015 by Johnson Duru • edited Jul 15, 2015 by SamTh3D3v

1 Answer

0

to update the list, implement the interfaceдля INotifyPropertyChanged

class UserData:  INotifyPropertyChanged
    {

     public event PropertyChangedEventHandler PropertyChanged;

     private string _Title;
     public string Title
       {
        get
            {
                return _Title;
            }
        set
            {
             if (_Title != value)
                {
                  _Title = value;
                  if (PropertyChanged != null)
                    {
                        PropertyChanged(this, new PropertyChangedEventArgs("Title"));
                    }
                }
            }
        }
    }
answered on Stack Overflow Jan 4, 2016 by Redwerk

User contributions licensed under CC BY-SA 3.0