Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

SetBinding does not work on real device (iOS) but only in simulator

$
0
0

I have a very strange problem with Xamarin.Forms. I create a composant named 'ExtSlider' then add into it one Slider and one Label. I set the binding of Slider to ExtSlider (code below) in order to update its values whenever we change MaxValue, MinValue, Value of my composant ExtSlider.
However, it works only in Simulator (iphone 5s 8.1) but not in real device iPod 5 8.1.1 .

Can anyone help me out of this problem? Any suggestion would be appreciated!

public class ExtSlider : ContentView
    {


        /// <summary>
        /// The minimum value property.
        /// </summary>
        public static readonly BindableProperty MinValueProperty = 
            BindableProperty.Create("MinValue", 
                typeof(double),           // property type 
                typeof(ExtSlider),    // this type
                0.0,                  // initial value
                BindingMode.OneWay,     // default binding
                null,                   // validation
                null);

        /// <summary>
        /// The max value property.
        /// </summary>
        public static readonly BindableProperty MaxValueProperty = 
            BindableProperty.Create("MaxValue", 
                typeof(double),           // property type 
                typeof(ExtSlider),    // this type
                1.0,                  // initial value
                BindingMode.OneWay,     // default binding
                null,                   // validation
                null);

        /// <summary>
        /// The value property.
        /// </summary>
        public static readonly BindableProperty ValueProperty =
            BindableProperty.Create("Value", 
                typeof(double),           // property type 
                typeof(ExtSlider),    // this type
                0.0,                  // initial value
                BindingMode.OneWay,     // default binding
                null,                   // validation
                null);

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        public double Value {
            get {
                return this.GetValue<double> (ValueProperty);
            }

            set {
                this.SetValue (ValueProperty, value);

                if (this.ValueChanged != null)
                    this.ValueChanged.Invoke (this, value);
            }
        }

        /// <summary>
        /// Gets or sets the minimum value.
        /// </summary>
        /// 
        public double MinValue {
            get {
                return this.GetValue<double> (MinValueProperty);
            }

            set {
                this.SetValue (MinValueProperty, value);

            }
        }

        /// <summary>
        /// Gets or sets the max value.
        /// </summary>
        /// <value>The max value.</value>
        public double MaxValue {
            get {
                return this.GetValue<double> (MaxValueProperty);
            }

            set {
                this.SetValue (MaxValueProperty, value);

            }
        }

        private Slider _mySlider = new Slider();
        private Label _myLabel = new Label ();


        public ExtSlider ()
        {
            //Setup binding
            _mySlider.BindingContext = this;
            _mySlider.SetBinding (Slider.ValueProperty,"Value");
            _mySlider.SetBinding (Slider.MaximumProperty,"MaxValue");
            _mySlider.SetBinding (Slider.MinimumProperty,"MinValue");

            _myLabel.BindingContext = _mySlider;
            _myLabel.SetBinding (Label.TextProperty,"Value",BindingMode.OneWay,null,"Value is : {0:F}");

            _mySlider.Unfocused+= (object sender, FocusEventArgs fea) => {
                System.Diagnostics.Debug.WriteLine("ExtSlider:" + "Unfocused");
            };

            System.Diagnostics.Debug.WriteLine("ExtSlider:" + "When init, Current value: "+this.Value);
            //init button and title
            this.Content = new StackLayout {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = 100,
                Children = {
                    this._mySlider,
                    this._myLabel
                }
            };
        }
    }

And here the declaration in my .xaml contentPage

<local:ExtSlider x:Name="slider" MaxValue="5" Value="2.5"></local:ExtSlider>


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>