private static void DisplayMultiplicatorChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { ValueSlider Sender = (ValueSlider)sender; Sender.StringValue = String.Format(Sender.Format, Sender.TempValue * Sender.DisplayMultiplicator); StepSizeChanged(sender, e); }
private static void StepSizeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { ValueSlider Sender = (ValueSlider)sender; string DecimalSeparator = NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator; string StepString = (Sender.StepSize * Sender.DisplayMultiplicator).ToString(); int Decimals = 0; if (StepString.Contains(DecimalSeparator)) { string DecimalPart = StepString.Split(new string[] { DecimalSeparator }, StringSplitOptions.None)[1]; while (DecimalPart.Length > 0 && DecimalPart[DecimalPart.Length - 1] == '0') { DecimalPart = DecimalPart.Substring(0, DecimalPart.Length - 1); } Decimals = DecimalPart.Length; } Sender.Decimals = Decimals; string Format = "{0:0}"; if (Decimals > 0) { Format = "{0:0."; for (int i = 0; i < Decimals; i++) { Format += "0"; } Format += "}"; } Sender.Format = Format; Sender.StringValue = String.Format(Sender.Format, Sender.TempValue * Sender.DisplayMultiplicator); }
static void MaxValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { ValueSlider Sender = (ValueSlider)sender; if (Sender.Value > (decimal)e.NewValue) { Sender.Value = (decimal)e.NewValue; } }
private static void StringValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { ValueSlider Sender = (ValueSlider)sender; if (Sender.IsPerformingManualEdit) { Sender.IsPerformingManualEdit = false; try { decimal NewValue = decimal.Parse((string)e.NewValue); Sender.Value = Math.Max(Math.Min(Math.Round(NewValue / Sender.DisplayMultiplicator / Sender.StepSize) * Sender.StepSize, Sender.MaxValue), Sender.MinValue); } catch { } Sender.StringValue = string.Format(Sender.Format, Sender.TempValue * Sender.DisplayMultiplicator); } }