Basically I need to do some calculations when the Maximum or Minimum properties change, but there's no event in the Slider control that allows me to look at it when this happens.
Any ideas?
Thanks!
Basically I need to do some calculations when the Maximum or Minimum properties change, but there's no event in the Slider control that allows me to look at it when this happens.
Any ideas?
Thanks!
Maximum is dependency property, so you can bind it to some property of view model.
You should know when you change those values - just move the notification job to the class which sets the Maximum and the Minimum (directly or indirectly via a binding).
When using a ViewModel, this would be a much cleaner way (letting the ViewModels do this job) - you could then use a Mediator like that one.
You can register to get events when a DP changes.
<Slider Loaded="OnSliderLoaded"/>
private void OnSliderLoaded(object sender, RoutedEventArgs e)
{
Slider slider = sender as Slider;
DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(Slider.MinimumProperty, typeof(Slider));
if (dpd != null)
{
dpd.AddValueChanged(slider, delegate
{
Debug.WriteLine("Minimimum changed:" + _slider.Minimum);
});
}
}