我有一个控制滑块值的 TwoWay 绑定:
<Slider Orientation="Vertical" Height="200" Value="{Binding Path=MapScale, Mode=TwoWay}" Maximum="{Binding MaxScale}" Minimum="{Binding MinScale}" StepFrequency="0.1" />
绑定在 ViewModel 中作为 DependencyProperty:
public static readonly DependencyProperty MapScaleProperty =
DependencyProperty.Register("MapScale", typeof(Double?), typeof(MappingPageViewModel), new PropertyMetadata(0.0));
public Double? MapScale
{
get { return GetValue(MapScaleProperty) as Double?; }
set { SetValue(MapScaleProperty, value); OnPropertyChanged("MapScale"); }
}
就像现在的代码一样,当我更新 MapScale(例如MapScale += .1
)时,滑块会正确更新。但是,如果我删除该OnPropertyChanged
方法(我印象SetValue
中已经调用过该方法),滑块将无法正确更新。
我错过了什么?