views:

26

answers:

3

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!

A: 

Maximum is dependency property, so you can bind it to some property of view model.

STO
+1  A: 

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.

winSharp93
I went with the first option because of some by-design restrictions in our code. Thanks for the help!
Carlo
+1  A: 

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);
        });
    }
}
Wallstreet Programmer