Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have to implement <code>INotifyPropertyChanged</code>, only then the changes will be updated in UI.</p> <p>Here are the modifications that I've done to your code.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.ComponentModel; using System.Collections.ObjectModel; namespace WpfApplication1 { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window, INotifyPropertyChanged { private Molecule _CurrentMolecule; public Molecule CurrentMolecule { get { return _CurrentMolecule; } set { _CurrentMolecule = value; OnPropertyChanged("CurrentMolecule"); Formulas = new ObservableCollection&lt;string&gt;(CurrentMolecule.FormulasList.ToList()); } } private ObservableCollection&lt;string&gt; _Formulas; public ObservableCollection&lt;string&gt; Formulas { get { return _Formulas; } set { _Formulas = value; OnPropertyChanged("Formulas"); } } public MainWindow() { InitializeComponent(); CurrentMolecule = new Molecule(); DataContext = this; } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } } </code></pre> <p>Edit: A better approach is to create a ViewModel and then bind it to the DataContext of the <code>Window</code>. </p> <p>Define a new class called <code>ViewModel</code> as below. Note you might want to change the namespace</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; using System.Collections.ObjectModel; namespace WpfApplication1 { public class ViewModel : INotifyPropertyChanged { #region Properties private Molecule _CurrentMolecule; public Molecule CurrentMolecule { get { return _CurrentMolecule; } set { _CurrentMolecule = value; OnPropertyChanged("CurrentMolecule"); Formulas = new ObservableCollection&lt;string&gt;(CurrentMolecule.FormulasList.ToList()); } } private ObservableCollection&lt;string&gt; _Formulas; public ObservableCollection&lt;string&gt; Formulas { get { return _Formulas; } set { _Formulas = value; OnPropertyChanged("Formulas"); } } #endregion #region Constructor public ViewModel() { CurrentMolecule = new Molecule(); } #endregion #region INotifyPropertyChanged implementation public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } #endregion } } </code></pre> <p>Modify the <code>MainWindow</code> code behind file as below</p> <pre><code>public MainWindow() { InitializeComponent(); DataContext = new ViewModel(); } </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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