I needed a trivial example of how INotifyPropertyChanged
is useful, but my demo app is going totally against my expectations.
namespace WpfApp2CS
{
public class ViewModel
{
public double Value { get; set; }
}
}
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp2CS"
Title="MainWindow" Width="300" Height="150"
x:Class="WpfApp2CS.MainWindow">
<Window.DataContext>
<local:ViewModel />
</Window.DataContext>
<StackPanel>
<Slider Value="{Binding Value, Mode=OneWayToSource}" />
<TextBlock Text="{Binding Value, Mode=OneWay}" />
</StackPanel>
</Window>
I was under the impression that the setter of Value
would be hit every time the slider moves, but the getter would only be hit once because ViewModel
doesn't raise INotifyPropertyChanged.PropertyChanged
. This is not the case; the text updates with every movement of the slider.