Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes. Implement the interface INotifyPropertyChanged. </p> <p>An example: </p> <p>MainWindow.xaml</p> <pre><code>&lt;Window x:Class="INotifyChangedDemo.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"&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="*"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="*"&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;Label Content="{Binding HitCount}"&gt;&lt;/Label&gt; &lt;Button Grid.Row="1" Click="Button_Click"&gt; Hit &lt;/Button&gt; &lt;/Grid&gt; </code></pre> <p></p> <hr> <p>MainWindow.xaml.cs</p> <pre><code>namespace INotifyChangedDemo { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { private MainViewModel _viewModel = new MainViewModel(); public MainWindow() { InitializeComponent(); DataContext = _viewModel; } private void Button_Click(object sender, RoutedEventArgs e) { _viewModel.HitCount = _viewModel.HitCount + 1; } } } </code></pre> <hr> <p>MainViewModel.cs</p> <pre><code>namespace INotifyChangedDemo { public class MainViewModel : INotifyPropertyChanged { private int _hitCount; public int HitCount { get { return _hitCount; } set { if (_hitCount == value) return; _hitCount = value; // Notify the listeners that Time property has been changed if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("HitCount")); } } } public event PropertyChangedEventHandler PropertyChanged; } } </code></pre> <p>For better implementation of INotifyChangedProperty, please refer to this thread: <a href="https://stackoverflow.com/questions/527602/automatically-inotifypropertychanged">Automatically INotifyPropertyChanged</a>.</p> <p>If you wanna know more about the MVVM pattern, please see here: <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/magazine/dd419663.aspx</a></p>
    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