private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Run run = (Run)d; if (INTERNAL_VisualTreeManager.IsElementInVisualTree(run)) { INTERNAL_HtmlDomManager.SetContentString(run, (string)e.NewValue); } }
static void Text_MethodToUpdateDom(DependencyObject d, object newValue) { var textBlock = (TextBlock)d; string newText = newValue as string; if (newText == null || newText == string.Empty) { newText = "\u00A0"; // We put a non-breaking space here because otherwise with string.Empty the Height of the TextBlock in HTML becomes 0. } INTERNAL_HtmlDomManager.SetContentString(textBlock, newText); }
private void DetachChild() { if (object.ReferenceEquals(this, this.Child)) // if ContentTemplate is null and Content is not an UIElement { INTERNAL_HtmlDomManager.SetContentString(this, string.Empty, removeTextWrapping: true); } else { INTERNAL_VisualTreeManager.DetachVisualChildIfNotNull(this.Child, this); } this.Child = null; }
static void Text_MethodToUpdateDom(DependencyObject d, object newValue) { var run = (Run)d; string newText = newValue as string; if (newText == null || newText == string.Empty) { newText = "\u00A0"; // We put a non-breaking space here because otherwise with string.Empty the Height of the TextBlock in HTML becomes 0. } newText = newText + "\u00A0"; // We add a space at the end of the text so that two <Run> tags do not appear to touch each other (eg. <Run>This is a</Run><Run>test.</Run>). INTERNAL_HtmlDomManager.SetContentString(run, newText); }
private void ChangeChild(object newChild) { this.DetachChild(); // Detach current child. UIElement newChildAsUIElement = newChild as UIElement; if (newChildAsUIElement != null) { INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(newChildAsUIElement, this); this.Child = newChildAsUIElement; } else { string contentAsString = newChild == null ? string.Empty : newChild.ToString(); INTERNAL_HtmlDomManager.SetContentString(this, contentAsString, removeTextWrapping: true); this.Child = this; // In the case where the child is not an UIElement, we consider the child to be this Control because we don't add a child (we directly set the content of this element). } }
//static void ContentTemplate_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) //{ // var contentControl = (ContentControl)d; // object newText = e.NewValue; // //todo: apply the new template to the content (if the content is set) // //if (INTERNAL_VisualTreeManager.IsElementInVisualTree(contentControl)) // // apply template //} /// <summary> /// Invoked when the value of the Content property changes. /// </summary> /// <param name="oldContent">The old value of the Content property.</param> /// <param name="newContent">The new value of the Content property.</param> protected virtual void OnContentChanged(object oldContent, object newContent) { if (!this.HasTemplate) { //----------------------------- // DETACH PREVIOUS CONTENT //----------------------------- if (oldContent is UIElement) { INTERNAL_VisualTreeManager.DetachVisualChildIfNotNull((UIElement)oldContent, this); } if (_dataTemplateRenderedContent != null) { INTERNAL_VisualTreeManager.DetachVisualChildIfNotNull(_dataTemplateRenderedContent, this); } _dataTemplateRenderedContent = null; //----------------------------- // ATTACH NEW CONTENT //----------------------------- if (newContent is UIElement) { INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached((UIElement)newContent, this); } else if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this)) { if (ContentTemplate != null) { // Apply the data template: _dataTemplateRenderedContent = ContentTemplate.INTERNAL_InstantiateFrameworkTemplate(); _dataTemplateRenderedContent.DataContext = newContent; INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(_dataTemplateRenderedContent, this); } else if (newContent != null) { // Show the string: INTERNAL_HtmlDomManager.SetContentString(this, newContent.ToString(), removeTextWrapping: true); } } } }
private void UpdateDomText(string text) { if (INTERNAL_OuterDomElement != null && Application.Current.TextMeasurementService.IsTextMeasureDivID(((INTERNAL_HtmlDomElementReference)INTERNAL_OuterDomElement).UniqueIdentifier)) { if (_isUpdatingDOM || _contentEditableDiv == null) { return; } INTERNAL_HtmlDomManager.SetContentString(this, text); return; } if (_isUpdatingDOM || _contentEditableDiv == null) { return; } INTERNAL_HtmlDomManager.SetContentString(this, Host.Text); }
protected internal override void INTERNAL_OnAttachedToVisualTree() { base.INTERNAL_OnAttachedToVisualTree(); INTERNAL_HtmlDomManager.SetContentString(this, this.Text); }