c# - Silverlight - Can't get ListBox to bind to my ObservableCollection -


I am trying to create a list box that updates the contents of that Objective Collection, whenever in that collection Anything changes, so this is the code I wrote for:

XAML:

   & Lt; / DataTemplate & gt; & Lt; /ListBox.ItemTemplate> & Lt; / ListBox & gt;  

C #:

  Public Supervision Collection & lt; Users & gt; ListOfUsers {Return (Observable Collection & lt; User & gt;) GetValue (listOfUsersProperty); } Set {set value (listOfUsersProperty, value); }} Public static Readonly DependencyProperty listOfUsersProperty = DependencyProperty.Register ("listOfUsers", typeof (ObservableCollection & lt; user & gt;), typeof (mainpage), null);  

And I have a WCF service that fills listOfUsers to arrange a call:

  zero repoService_FindAllUsersCompleted (object sender, FindAllUsersCompletedEventArgs e) {this .listOfUsers = New ObservableCollection & LT; Users & gt; (); Forchha (User You In E. Result) {listOfUsers.Add (U); } // Make sure that this prostitute is made (user u in these listoffers) {MessageBox.Show (u.LastName); }}  

The list box does not ever populate with anything I think ObservableCollection is actually all my user in it, my problem may be with XAML.

After

You are deprecating part of your itemsSource {binding}

  & lt; ListBox X:. Name = "UserListTest" height = "300" width = "200" item source = "{binding listoffice}" & gt; & Lt; ListBox.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; Text block text = "{binding final name}" /> & Lt; / DataTemplate & gt; & Lt; /ListBox.ItemTemplate> & Lt; / ListBox & gt;  

In addition, you may not need a DependencyProperty for your list, you receive what you have to do with a property on a class that applies the INotifyPropertyChanged Needs can be enabled. This can be a better option unless you need dependency property (and goes with it) for any other reason.

For example

  public class MyViewModel: INotifyPropertyChanged {Personal Supervision Collection & lt; Users & gt; _listOfUsers; Public Event Threaded ChangedEventHandler Property changed; Public supervision & lt; Users & gt; ListOfUsers {get _listOfUsers; } Set {if (_listOfUsers == value) returns; _listOfUsers = value; If (property has changed! = Null) by changing property (this, new Property Converted Entities ("Listoffers")); }}}  

Comments