« Posts under Silverlight

Silverlight 5 Slider Binding Bug

As described here
http://forums.silverlight.net/t/119338.aspx/1

Silverlight 5 (and 4) has a bug with it’s slider control. You can not bind to the Maximum and Minimum properties of the control. To get around this I have a simple solution with the code below. Basically just inherit from Slider and add two custom dependency properties and register for the on-changed events. In the callback you can manually set the minimum and maximum values of the slider instead of bindings.

This is a pain but seems to be a easy and clean solutions.

C#
 
public class CustomSlider : Slider
    {
 
        public static readonly DependencyProperty MinimumBugFixProperty = DependencyProperty.Register("MinimumBugFix", typeof(double), typeof(CustomSlider), new FrameworkPropertyMetadata(0, new PropertyChangedCallback(OnUpdateSliderRange)));
        public static readonly DependencyProperty MaximumBugFixProperty = DependencyProperty.Register("MaximumBugFix", typeof(double), typeof(CustomSlider), new FrameworkPropertyMetadata(100, new PropertyChangedCallback(OnUpdateSliderRange)));
 
 
        public CustomSlider()
        {
 
        }
 
        public double MinimumBugFix
        {
            get { return (double)GetValue(MinimumBugFixProperty); }
            set { SetValue(MinimumBugFixProperty, value); }
        }
 
        public double MaximumBugFix
        {
            get { return (double)GetValue(MaximumBugFixProperty); }
            set { SetValue(MaximumBugFixProperty, value); }
        }
 
        private static void OnUpdateSliderRange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CustomSlider slider = d as CustomSlider;
            if (slider != null)
            {
                if(slider.Maximum != slider.MaximumBugFix)
                    slider.Maximum = slider.MaximumBugFix;
                if(slider.Minimum != slider.MinimumBugFix)
                    slider.Minimum = slider.MinimumBugFix;
            }
        }
}

WPF to Silverlight porting…

My biggest WTF moment so far with silverlight.. there is no Visibility.Hidden enum value.

So much for reusing all those valueconverters.. oh the pain!

C#
 
namespace System.Windows
{
    // Summary:
    //     Specifies the display state of an element.
    public enum Visibility
    {
        // Summary:
        //     Display the element.
        Visible = 0,
        //
        // Summary:
        //     Do not display the element, and do not reserve space for it in layout.
        Collapsed = 1,
    }
}