Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The code you posted looks fine to me. I replicated your code (in C#, but I tried to keep it as close to your code as possible) and it just worked. The only code you didn't post is the event handler of the <code>Add</code> button. Did you check that it is actually called and that a new item is added to the collection?</p> <p>Anyway here is my code, maybe you can spot where the difference is between this and your version:</p> <p>CollectionOfBlogs.cs:</p> <pre><code>public class CollectionOfBlogs : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private string _FullName; public string FullName { get { return this._FullName; } set { if (this._FullName != value) { this._FullName = value; this.OnPropertyChanged("FullName"); } } } public CollectionOfBlogs(string name) { this._FullName = name; } public virtual void OnPropertyChanged(string propertyName) { if (this.PropertyChanged != null) { this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public override string ToString() { return this._FullName; } } </code></pre> <p>ITRSBlogs.cs:</p> <pre><code>public class ITRSBlogs { public ObservableCollection&lt;CollectionOfBlogs&gt; blogNamesList = new ObservableCollection&lt;CollectionOfBlogs&gt;(); public void AddBlog(string fullName) { this.blogNamesList.Add(new CollectionOfBlogs(fullName)); } public void FillBlogList() { this.blogNamesList.Clear(); this.AddBlog("First blog"); this.AddBlog("Another blog"); } } </code></pre> <p>MainWindow.xaml:</p> <pre><code>&lt;Window x:Class="ObservableRefreshDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"&gt; &lt;Grid&gt; &lt;ListBox Name="BloggingMenuListBox"/&gt; &lt;Button Content="Add" Height="23" HorizontalAlignment="Left" Margin="154,276,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /&gt; &lt;TextBox Height="23" HorizontalAlignment="Left" Margin="12,276,0,0" Name="txtName" VerticalAlignment="Top" Width="120" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>MainWindow.xaml.cs:</p> <pre><code>public partial class MainWindow : Window { private ITRSBlogs blogClass = new ITRSBlogs(); public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { this.blogClass.FillBlogList(); this.BloggingMenuListBox.ItemsSource = this.blogClass.blogNamesList; } private void button1_Click(object sender, RoutedEventArgs e) { this.blogClass.AddBlog(this.txtName.Text); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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