예제 #1
0
            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();
                }
            }
예제 #2
0
            private void TrackAndGetValue <T> (FrameworkElement source, DependencyProperty localProp, DependencyProperty textElementAttachedProp, out T foundValue)
            {
                if (source.ReadLocalValue(localProp) != DependencyProperty.UnsetValue)
                {
                    foundValue = (T)source.GetValue(localProp);
                }
                else if (source.ReadLocalValue(textElementAttachedProp) != DependencyProperty.UnsetValue)
                {
                    foundValue = (T)source.GetValue(textElementAttachedProp);
                }
                else
                {
                    foundValue = (T)source.GetValue(localProp);
                }

                m_watcher.Watch(localProp);
                m_watcher.Watch(textElementAttachedProp);
            }