private static void Update(LedPresenter lp, string val) { String toPrint = val; if (lp != null) { if (val.Length > lp.DigitCount) { toPrint = toPrint.Substring(0, lp.DigitCount); } switch (lp.Align) { case TextAlignment.Left: toPrint = toPrint.PadRight(lp.DigitCount); break; case TextAlignment.Right: toPrint = toPrint.PadLeft(lp.DigitCount); break; case TextAlignment.Center: toPrint = toPrint.PadLeft(lp.DigitCount / 2); toPrint = toPrint.PadRight(lp.DigitCount / 2); break; } lp.SetValue(MaskValueProperty, new string('A', lp.DigitCount)); lp.SetValue(ValueProperty, toPrint); } }
private static void ValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { String val = Convert.ToString(e.NewValue); LedPresenter lp = o as LedPresenter; Update(lp, val); }