public TextParentItem(PathFollowingContentDisplayer parent, TextBlock source) { m_renderTarget = source; m_parent = parent; m_dataSource = source.Text; m_watcher = new DPWatcher(source); TrackAndGetValue(source, TextBlock.FontFamilyProperty, TextElement.FontFamilyProperty, out FontFamily fontFamily); TrackAndGetValue(source, TextBlock.FontStretchProperty, TextElement.FontStretchProperty, out FontStretch fontStretch); TrackAndGetValue(source, TextBlock.FontStyleProperty, TextElement.FontStyleProperty, out FontStyle fontStyle); TrackAndGetValue(source, TextBlock.FontWeightProperty, TextElement.FontWeightProperty, out FontWeight fontWeight); TrackAndGetValue(source, TextBlock.FontSizeProperty, TextElement.FontSizeProperty, out m_foundFontSize); m_watcher.Watch(TextBlock.TextProperty); m_foundTypeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch); m_watcher.WatchedValueChanged += _DoNeedsRender; void _DoNeedsRender(object _sender, EventArgs <object> _e) { // The text itself updated if (_e.Value is string text) { m_dataSource = text; this.ResetChildren(); } this.TriggerNeedsRender(); } }
public TextParentItem(PathFollowingContentDisplayer source, string text) { m_parent = source; m_dataSource = text; m_watcher = new DPWatcher(source); TrackAndGetValue(source, Control.FontFamilyProperty, TextElement.FontFamilyProperty, out FontFamily fontFamily); TrackAndGetValue(source, Control.FontStretchProperty, TextElement.FontStretchProperty, out FontStretch fontStretch); TrackAndGetValue(source, Control.FontStyleProperty, TextElement.FontStyleProperty, out FontStyle fontStyle); TrackAndGetValue(source, Control.FontWeightProperty, TextElement.FontWeightProperty, out FontWeight fontWeight); TrackAndGetValue(source, Control.FontSizeProperty, TextElement.FontSizeProperty, out m_foundFontSize); m_foundTypeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch); m_watcher.WatchedValueChanged += _DoNeedsRender; void _DoNeedsRender(object _sender, EventArgs _e) => this.TriggerNeedsRender(); }