| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System.Windows;
- using System.Windows.Controls;
- namespace Muchinfo.WPF.Controls.Zoom
- {
- /// <summary>
- /// Class ZoomFontText.
- /// </summary>
- public class ZoomFontText : Control
- {
- static ZoomFontText()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(ZoomFontText), new FrameworkPropertyMetadata(typeof(ZoomFontText)));
- }
- public double FontCount
- {
- get { return (double)GetValue(FontCountProperty); }
- set { SetValue(FontCountProperty, value); }
- }
- // Using a DependencyProperty as the backing store for FontCount. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty FontCountProperty =
- DependencyProperty.Register("FontCount", typeof(double), typeof(ZoomFontText), new PropertyMetadata(2d));
- /// <summary>
- /// 放大倍数
- /// </summary>
- public double ZoomFontSize
- {
- get { return (double)GetValue(ZoomFontSizeProperty); }
- set { SetValue(ZoomFontSizeProperty, value); }
- }
- // Using a DependencyProperty as the backing store for ZoomSize. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty ZoomFontSizeProperty =
- DependencyProperty.Register("ZoomFontSize", typeof(double), typeof(ZoomFontText), new PropertyMetadata(2d));
- public string NormalText
- {
- get { return (string)GetValue(NormalTextProperty); }
- set { SetValue(NormalTextProperty, value); }
- }
- // Using a DependencyProperty as the backing store for NormalText. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty NormalTextProperty =
- DependencyProperty.Register("NormalText", typeof(string), typeof(ZoomFontText), new PropertyMetadata(""));
- /// <summary>
- /// 放大文本
- /// </summary>
- public string ZoomText
- {
- get { return (string)GetValue(ZoomTextProperty); }
- set { SetValue(ZoomTextProperty, value); }
- }
- // Using a DependencyProperty as the backing store for ZoomText. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty ZoomTextProperty =
- DependencyProperty.Register("ZoomText", typeof(string), typeof(ZoomFontText), new PropertyMetadata(""));
- public string Text
- {
- get { return (string)GetValue(TextProperty); }
- set { SetValue(TextProperty, value); }
- }
- // Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty TextProperty =
- DependencyProperty.Register("Text", typeof(string), typeof(ZoomFontText), new PropertyMetadata("", OnTextChange));
- private static void OnTextChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var self = d as ZoomFontText;
- if (self == null) return;
- // SetViewBoxWidthHeight(self);
- var text = e.NewValue as string;
- if (string.IsNullOrWhiteSpace(text)) return;
- if (text.Length < self.FontCount)
- {
- self.NormalText = text;
- self.ZoomText = string.Empty;
- return;
- }
- self.NormalText = text.Substring(0, text.Length - (int)self.FontCount);
- self.ZoomText = text.Substring(text.Length - (int)self.FontCount);
- }
- }
- }
|