Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding observable collection to ListBox in XAML
    primarykey
    data
    text
    <p>I've spent lots of hours with this problem.</p> <p>I have a class with data: </p> <pre><code>class userClass : INotifyPropertyChanged { public int _key; private string _fullName; private string _nick; public int key { get{return _key;} set { _key = value; NotifyPropertyChanged("key"); } } private string nick { get { return _nick; } set { _nick = value; NotifyPropertyChanged("nick"); } } private string fullName { get { return _fullName; } set { _fullName = value; NotifyPropertyChanged("fullName"); } } public userClass() { nick = "nickname"; fullName = "fullname"; } public userClass(String nick, String name, int key) { this.nick = nick; this.fullName = name; } //INotifzPropertyChanged implementation public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public override string ToString() { return string.Format("{0} {1}, {2}", key, nick, fullName); } } </code></pre> <p>Next I have a class with observablecollection of userClass class:</p> <pre><code>class userListClass : ObservableCollection&lt;userClass&gt; { public userListClass(){} //public override void Add(userClass user) //{ // //user.PropertyChanged += new PropertyChangedEventHandler(user); // base.Add(user); //} ~userListClass() { //Serialize(); } public void Serialize(ObservableCollection&lt;userClass&gt; usersColl) { FileStream fs = new FileStream("DataFile.dat", FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); try { formatter.Serialize(fs, usersColl); } catch (SerializationException e) { Console.WriteLine("Failed to serialize. Reason: " + e.Message); throw; } finally { fs.Close(); } } public void Deserialize() { FileStream fs = new FileStream("DataFile.dat", FileMode.Open); try { BinaryFormatter formatter = new BinaryFormatter(); //users = (Hashtable) formatter.Deserialize(fs); //usersColl = (ObservableCollection&lt;userClass&gt;)formatter.Deserialize(fs); } catch (SerializationException e) { MessageBox.Show(" Error: " + e.Message); throw; } finally { fs.Close(); } } public override string ToString() { return "test"; //return base.ToString(); } } </code></pre> <p>In fact, after lots of testing an editing, big part of code doesn't work, like serialization. But it is not necessary for data binding and binding is what i am solving now.</p> <p>So i have this collection and want to bind it to listBox. I tried several ways, but haven't got it to work. </p> <p>The last one I tried gave me the write error: </p> <blockquote> <p><em>The resource 'users' cannot be resolved.</em></p> </blockquote> <pre><code>&lt;ListBox Grid.Column="0" Name="userViewLeft" ItemsSource="{Binding Source={StaticResource users} }" /&gt; </code></pre>
    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.
 

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