Пример #1
0
        static private void EndAnimation(RangeBase rangeBase)
        {
            // Reset last update time
            SetLastUpdateTime(rangeBase, null);

            // Stop animation (set to null)
            rangeBase.BeginAnimation(RangeBase.ValueProperty, null, HandoffBehavior.SnapshotAndReplace);
        }
Пример #2
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            RangeBase slider = GetTemplateChild("PART_RedSlider") as RangeBase;

            if (slider != null)
            {
                Binding binding = new Binding()
                {
                    Path   = new PropertyPath("Red"),
                    Source = this,
                    Mode   = BindingMode.TwoWay
                };
                slider.SetBinding(RangeBase.ValueProperty, binding);
                slider.Maximum = RGBMaxValue;
            }

            slider = GetTemplateChild("PART_GreenSlider") as RangeBase;
            if (slider != null)
            {
                Binding binding = new Binding()
                {
                    Path   = new PropertyPath(nameof(Green)),
                    Source = this,
                    Mode   = BindingMode.TwoWay
                };
                slider.SetBinding(RangeBase.ValueProperty, binding);
                slider.Maximum = RGBMaxValue;
            }

            slider = GetTemplateChild("PART_BlueSlider") as RangeBase;
            if (slider != null)
            {
                Binding binding = new Binding()
                {
                    Path   = new PropertyPath(nameof(Blue)),
                    Source = this,
                    Mode   = BindingMode.TwoWay
                };
                slider.SetBinding(RangeBase.ValueProperty, binding);
                slider.Maximum = RGBMaxValue;
            }

            SolidColorBrush brush = GetTemplateChild("PART_PreviewBrush") as SolidColorBrush;

            if (brush != null)
            {
                Binding bd = new Binding
                {
                    Path   = new PropertyPath(nameof(brush.Color)),
                    Source = brush,
                    Mode   = BindingMode.OneWayToSource
                };
                SetBinding(ColorPicker.ColorProperty, bd);
            }
        }
Пример #3
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _plus   = base.GetTemplateChild(@"PART_Plus") as ButtonBase;
            _minus  = base.GetTemplateChild(@"PART_Minus") as ButtonBase;
            _slider = base.GetTemplateChild(@"PART_Slider") as RangeBase;

            if (_plus != null)
            {
                _plus.Click  += plus_Click;
                _plus.ToolTip = Properties.Resources.ZoomControl_ZoomInTooltip;
            }
            if (_minus != null)
            {
                _minus.Click  += minus_Click;
                _minus.ToolTip = Properties.Resources.ZoomControl_ZoomOutTooltip;
            }
            if (_slider != null)
            {
                BindingOperations.SetBinding(_slider, RangeBase.ValueProperty, new Binding {
                    Path = new PropertyPath(ValueProperty.Name), RelativeSource = RelativeSource.TemplatedParent
                });
                BindingOperations.SetBinding(_slider, RangeBase.MinimumProperty, new Binding {
                    Path = new PropertyPath(MinimumProperty.Name), RelativeSource = RelativeSource.TemplatedParent
                });
                BindingOperations.SetBinding(_slider, RangeBase.MaximumProperty, new Binding {
                    Path = new PropertyPath(MaximumProperty.Name), RelativeSource = RelativeSource.TemplatedParent
                });
                BindingOperations.SetBinding(_slider, RangeBase.LargeChangeProperty, new Binding {
                    Path = new PropertyPath(LargeChangeProperty.Name), RelativeSource = RelativeSource.TemplatedParent
                });
                BindingOperations.SetBinding(_slider, RangeBase.SmallChangeProperty, new Binding {
                    Path = new PropertyPath(SmallChangeProperty.Name), RelativeSource = RelativeSource.TemplatedParent
                });
                BindingOperations.SetBinding(_slider, RangeBase.MaximumProperty, new Binding {
                    Path = new PropertyPath(MaximumProperty.Name), RelativeSource = RelativeSource.TemplatedParent
                });

                if (_slider is Slider)
                {
                    BindingOperations.SetBinding(_slider, Slider.TicksProperty,
                                                 new Binding
                    {
                        Path           = new PropertyPath(TicksProperty.Name),
                        RelativeSource = RelativeSource.TemplatedParent
                    });
                    BindingOperations.SetBinding(_slider, Slider.TickFrequencyProperty,
                                                 new Binding
                    {
                        Path           = new PropertyPath(TickFrequencyProperty.Name),
                        RelativeSource = RelativeSource.TemplatedParent
                    });
                }
            }
        }
        // Token: 0x060027BA RID: 10170 RVA: 0x000BA8A4 File Offset: 0x000B8AA4
        internal virtual void SetValueCore(double val)
        {
            RangeBase rangeBase = (RangeBase)base.Owner;

            if (val < rangeBase.Minimum || val > rangeBase.Maximum)
            {
                throw new ArgumentOutOfRangeException("val");
            }
            rangeBase.Value = val;
        }
Пример #5
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();


            _valueIndicator = (RangeBase)GetTemplateChild("PART_ValueIndicator");
            _valueTextBlock = (TextBlock)GetTemplateChild("PART_ValueTextBlock");

            UpdateStates(false);
        }
Пример #6
0
        private static int GetConfigValue(RangeBase sli, TextBox txtBox)
        {
            var value = (int)Math.Round(sli.Value);

            if (!Regex.IsMatch(txtBox.Text, value.ToString()))
            {
                txtBox.Text = value.ToString();
            }

            return(value);
        }
 public static void SetRangeValue(RangeBase RngBse, double V)
 {
     if (RngBse.Dispatcher.CheckAccess())
     {
         RngBse.Value = V;
     }
     else
     {
         RngBse.Dispatcher.Invoke(new Action <RangeBase, double>(SetRangeValue), RngBse, V);
     }
 }
Пример #8
0
        public override void OnApplyTemplate()
        {
//            _actualValueIndicator = (RangeBase)GetTemplateChild("PART_ActualValueIndicator");
//            _actualValueTextBlock = (TextBlock)GetTemplateChild("PART_ActualValueTextBlock");
//            _objectiveValueIndicator = (RangeBase)GetTemplateChild("PART_ObjectiveValueIndicator");
//            _objectiveValueTextBlock = (TextBlock)GetTemplateChild("PART_ObjectiveValueTextBlock");
            _valueIndicator = (RangeBase)GetTemplateChild("PART_ValueIndicator");
            _valueTextBlock = (TextBlock)GetTemplateChild("PART_ValueTextBlock");

            base.OnApplyTemplate();
        }
        /// <summary>
        /// Helper function for IRangeValueProvider.SetValue to provide a way for drive classes to have
        /// custom way of implementing it.
        /// </summary>
        /// <param name="val"></param>
        virtual internal void SetValueCore(double val)
        {
            RangeBase owner = (RangeBase)Owner;

            if (val < owner.Minimum || val > owner.Maximum)
            {
                throw new ArgumentOutOfRangeException("val");
            }

            owner.Value = (double)val;
        }
 public static double GetRangeValue(RangeBase RngBse)
 {
     if (RngBse.Dispatcher.CheckAccess())
     {
         return(RngBse.Value);
     }
     else
     {
         return((double)RngBse.Dispatcher.Invoke(new Func <RangeBase, double>(GetRangeValue), RngBse));
     }
 }
Пример #11
0
        /// <summary>
        /// Generates control fields
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="classType">Type of the class.</param>
        /// <param name="method">The initialize method.</param>
        /// <param name="generateField">if set to <c>true</c> [generate field].</param>
        /// <returns></returns>
        public override CodeExpression Generate(DependencyObject source, CodeTypeDeclaration classType, CodeMemberMethod method, bool generateField)
        {
            CodeExpression fieldReference = base.Generate(source, classType, method, generateField);
            RangeBase      rangeBase      = source as RangeBase;

            CodeComHelper.GenerateFieldDoubleToFloat(method, fieldReference, source, RangeBase.MinimumProperty);
            CodeComHelper.GenerateFieldDoubleToFloat(method, fieldReference, source, RangeBase.MaximumProperty);
            CodeComHelper.GenerateFieldDoubleToFloat(method, fieldReference, source, RangeBase.ValueProperty);
            CodeComHelper.GenerateFieldDoubleToFloat(method, fieldReference, source, RangeBase.SmallChangeProperty);
            CodeComHelper.GenerateFieldDoubleToFloat(method, fieldReference, source, RangeBase.LargeChangeProperty);
            return(fieldReference);
        }
Пример #12
0
        private static object CoerceMinimum(DependencyObject d, object value)
        {
            RangeBase ctrl = (RangeBase)d;
            double    max  = ctrl.Maximum;

            if ((double)value > max)
            {
                return(max);
            }

            return(value);
        }
Пример #13
0
        private static object CoerceMaximum(DependencyObject d, object baseValue)
        {
            RangeBase rangeBase   = (RangeBase)d;
            double    returnValue = baseValue is double?(double)baseValue : double.NaN;
            double    minimum     = rangeBase.Minimum;

            if (!double.IsNaN(minimum) && returnValue < minimum)
            {
                return(minimum);
            }
            return(returnValue);
        }
Пример #14
0
        void IRangeValueProvider.SetValue(double value)
        {
            RangeBase rangeBase = (RangeBase)Owner;

            if (!rangeBase.IsEnabled)
            {
                throw new ElementNotEnabledException();
            }

            SetFocus();
            rangeBase.Value = value;
        }
Пример #15
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();


            _actualValueIndicator    = (RangeBase)GetTemplateChild("PART_ActualValueIndicator");
            _actualValueTextBlock    = (TextBlock)GetTemplateChild("PART_ActualValueTextBlock");
            _objectiveValueIndicator = (RangeBase)GetTemplateChild("PART_ObjectiveValueIndicator");
            _objectiveValueTextBlock = (TextBlock)GetTemplateChild("PART_ObjectiveValueTextBlock");
            _dragDropPanel           = (Panel)GetTemplateChild("PART_DragDropPanel");

            UpdateStates(false);
        }
        private void UpdateThickness(RangeBase slider, DependencyProperty property, bool horizontal)
        {
            var newValue = slider.Value;

            foreach (var element in Controls)
            {
                var current = (Thickness)element.GetValue(property);
                var updated = horizontal
                    ? new Thickness(newValue, current.Top, newValue, current.Bottom)
                    : new Thickness(current.Left, newValue, current.Right, newValue);
                element.SetValue(property, updated);
            }
        }
Пример #17
0
        public void SetValue(double val)
        {
            if (!this.IsEnabled())
            {
                throw new ElementNotEnabledException();
            }
            RangeBase owner = (RangeBase)this.Owner;

            if (val < owner.Minimum || val > owner.Maximum)
            {
                throw new ArgumentOutOfRangeException(nameof(val));
            }
            owner.Value = val;
        }
        private void SetBinding(string childPartName, string propertyName)
        {
            RangeBase slider = GetTemplateChild(childPartName) as RangeBase;

            if (slider != null)
            {
                // bind to the red property in the control using a two-way binding
                Binding binding = new Binding(propertyName);
                binding.Source = this;
                binding.Mode   = BindingMode.TwoWay;

                slider.SetBinding(RangeBase.ValueProperty, binding);
            }
        }
Пример #19
0
 private static void AlterValue([NotNull] RangeBase slider, bool value, [CanBeNull] ICommand run)
 {
     if (value)
     {
         slider.Value += 0.04 + (1 - slider.Value) * 0.03;
         if (slider.Value >= 1d)
         {
             run?.Execute(null);
         }
     }
     else
     {
         slider.Value *= 0.8 - 0.01;
     }
 }
Пример #20
0
 private void ProgressGo(RangeBase Bar, float To, bool WithAnimation)
 {
     if (!WithAnimation)
     {
         if (m_Storyboard != null)
         {
             m_Storyboard.Stop();
             Bar.Value = To;
         }
     }
     else
     {
         AnimateProgressBar(Bar, To);
     }
 }
Пример #21
0
        public virtual void TestHasKeyboardFocusAfterPattern()
        {
            RangeBase fe = CreateConcreteFrameworkElement() as RangeBase;

            AutomationPeer      peer     = FrameworkElementAutomationPeer.CreatePeerForElement(fe);
            IRangeValueProvider provider = null;

            CreateAsyncTest(fe,
                            () => {
                provider = (IRangeValueProvider)peer.GetPattern(PatternInterface.RangeValue);
                Assert.IsNotNull(provider, "#0");
            },
                            () => provider.SetValue(.5),
                            () => Assert.IsTrue(peer.HasKeyboardFocus(), "#1"));
        }
Пример #22
0
        //
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            RangeBase slider = GetTemplateChild("PART_RedSlider") as RangeBase;

            //注意使用的是System.Windows.Controls.Primitives.RangeBase类(Slider类继承自该类)而不是Slider类。因为RangeBase类提供了需要的
            //最小功能——在本例中是指Value属性。通过尽可能提高代码的通用性,控件使用者可获得更大自由
            //例如,现在可提供自定义模板,使用不同的派生自RangeBase类的控件代替颜色滑动条

            if (slider != null)
            {
                Binding binding = new Binding("Red");
                binding.Source = this;
                binding.Mode   = BindingMode.TwoWay;
                slider.SetBinding(RangeBase.ValueProperty, binding);
            }
            slider = GetTemplateChild("PART_GreenSlider") as RangeBase;
            if (slider != null)
            {
                Binding binding = new Binding("Green");
                binding.Source = this;
                binding.Mode   = BindingMode.TwoWay;
                slider.SetBinding(RangeBase.ValueProperty, binding);
            }
            slider = GetTemplateChild("PART_BlueSlider") as RangeBase;
            if (slider != null)
            {
                Binding binding = new Binding("Blue");
                binding.Source = this;
                binding.Mode   = BindingMode.TwoWay;
                slider.SetBinding(RangeBase.ValueProperty, binding);
            }

            SolidColorBrush brush = GetTemplateChild("PART_PreviewBrush") as SolidColorBrush;

            if (brush != null)
            {
                Binding binding = new Binding("Color");
                binding.Source = brush;
                binding.Mode   = BindingMode.OneWayToSource;
                this.SetBinding(ColorPicker.ColorProperty, binding);
            }
            //因为SolidColorBrush画刷没有包含SetBinding()方法(该方法是在FrameworkElement类中定义的)。一个比较容易的变通方法是为
            //ColorPicker.Color属性创建绑定表达式,使用指向源方向的单向绑定。这样,当颜色拾取器的颜色改变后,将自动更新画刷
        }
Пример #23
0
        private static object CoerceValue(DependencyObject d, object baseValue)
        {
            RangeBase rangeBase   = (RangeBase)d;
            double    returnValue = baseValue is double?(double)baseValue : Convert.ToDouble(baseValue);
            double    minimum     = rangeBase.Minimum;

            if (!double.IsNaN(minimum) && returnValue < minimum)
            {
                return(minimum);
            }
            double maximum = rangeBase.Maximum;

            if (!double.IsNaN(maximum) && returnValue > maximum)
            {
                return(maximum);
            }
            return(returnValue);
        }
Пример #24
0
        internal static object ConstrainToRange(RangeBase rangeBase, double value)
        {
            var minimum = rangeBase.Minimum;

            if (value < minimum)
            {
                return(minimum);
            }

            var maximum = rangeBase.Maximum;

            if (value > maximum)
            {
                return(maximum);
            }

            return(value);
        }
Пример #25
0
        internal static object ConstrainToRange(RangeBase rangeBase, double value)
        {
            double minimum = rangeBase.Minimum;
            double num     = value;

            if (num < minimum)
            {
                return(minimum);
            }

            double maximum = rangeBase.Maximum;

            if (num > maximum)
            {
                return(maximum);
            }

            return(value);
        }
Пример #26
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            RangeBase slider = GetTemplateChild("PART_RedSlider") as RangeBase;

            if (slider != null)
            {
                Binding binding = new Binding();
                binding.Path   = new PropertyPath("Red");
                binding.Source = this;
                binding.Mode   = BindingMode.TwoWay;
                slider.SetBinding(RangeBase.ValueProperty, binding);
            }
            slider = GetTemplateChild("PART_GreenSlider") as RangeBase;
            if (slider != null)
            {
                Binding binding = new Binding();
                binding.Path   = new PropertyPath("Green");
                binding.Source = this;
                binding.Mode   = BindingMode.TwoWay;
                slider.SetBinding(RangeBase.ValueProperty, binding);
            }
            slider = GetTemplateChild("PART_BlueSlider") as RangeBase;
            if (slider != null)
            {
                Binding binding = new Binding();
                binding.Path   = new PropertyPath("Blue");
                binding.Source = this;
                binding.Mode   = BindingMode.TwoWay;
                slider.SetBinding(RangeBase.ValueProperty, binding);
            }

            SolidColorBrush brush = GetTemplateChild("PART_PreviewBrush") as SolidColorBrush;

            if (brush != null)
            {
                Binding binding = new Binding();
                binding.Path   = new PropertyPath("Color");
                binding.Source = brush;
                binding.Mode   = BindingMode.TwoWay;
                this.SetBinding(ColorPicker.ColorProperty, binding);
            }
        }
Пример #27
0
 public static string GetToolTipFormat(RangeBase element)
 => (string)element.GetValue(ToolTipFormatProperty);
Пример #28
0
 public static void SetToolTipFormat(RangeBase element, string value)
 => element.SetValue(ToolTipFormatProperty, value);
Пример #29
0
 public static bool GetOnlyShowFocusVisualWhileDragging(RangeBase element)
 => (bool)element.GetValue(OnlyShowFocusVisualWhileDraggingProperty);
Пример #30
0
 public static void SetOnlyShowFocusVisualWhileDragging(RangeBase element, bool value)
 => element.SetValue(OnlyShowFocusVisualWhileDraggingProperty, value);