/// <summary> /// Defines the value of the slider with an input of degrees from 0 to 360 (full circle). /// </summary> /// <param name="newValue">A degree value between 0 and 360</param> /// <param name="isDegrees">If true, degrees will be converted to a slider value. If false, the value /// will be set as the slider value.</param> private void SetSliderValue(double newValue, bool isDegrees) { double oldValue = currentValue; if (!isDegrees && (newValue < minimumValue || newValue > maximumValue)) { if (overflowValueToMinimum) { SetSliderValue(minimumValue, false); } else { SetSliderValue(maximumValue, false); } return; } if (isDegrees) { // Calculate the slider value according to minimum and maximum values currentValue = (int)(minimumValue + (maximumValue - minimumValue) * newValue / 360); } else { currentValue = Convert.ToInt32(newValue); newValue = newValue / (maximumValue - minimumValue) * 360; } // Update the UI thread Dispatcher.BeginInvoke(() => { Slider.EndAngle = newValue; // Visually update the slider }); // Optionally show the calculated slider value on the control if (ShowSliderValue) { // Update the UI thread Dispatcher.BeginInvoke(() => { SliderValueTextBox.Text = currentValue.ToString(); }); } // If the SliderValueChanged event is already initialized... if (SliderValueChanged != null) { //... raise a SliderValueChanged event with the corresponding data SliderValueChangedEventArgs newData = new SliderValueChangedEventArgs(oldValue, newValue); SliderValueChanged(this, newData); } }
/// <summary> /// Defines the value of the slider with an input of degrees from 0 to 360 (full circle). /// </summary> /// <param name="newValue">A degree value between 0 and 360</param> /// <param name="isDegrees">If true, degrees will be converted to a slider value. If false, the value /// will be set as the slider value.</param> private void SetSliderValue(double newValue, bool isDegrees) { double oldValue = currentValue; if(!isDegrees && (newValue < minimumValue || newValue > maximumValue)) { if (overflowValueToMinimum) SetSliderValue(minimumValue, false); else SetSliderValue(maximumValue, false); return; } if (isDegrees) // Calculate the slider value according to minimum and maximum values currentValue = (int)(minimumValue + (maximumValue - minimumValue) * newValue / 360); else { currentValue = Convert.ToInt32(newValue); newValue = newValue / (maximumValue - minimumValue) * 360; } // Update the UI thread Dispatcher.BeginInvoke(() => { Slider.EndAngle = newValue; // Visually update the slider }); // Optionally show the calculated slider value on the control if (ShowSliderValue) // Update the UI thread Dispatcher.BeginInvoke(() => { SliderValueTextBox.Text = currentValue.ToString(); }); // If the SliderValueChanged event is already initialized... if (SliderValueChanged != null) { //... raise a SliderValueChanged event with the corresponding data SliderValueChangedEventArgs newData = new SliderValueChangedEventArgs(oldValue, newValue); SliderValueChanged(this, newData); } }