private Inline CloneInline(Inline inline) { Inline retVal = null; if (inline is LineBreak) { retVal = new LineBreak(); } else if (inline is Span) { retVal = new Span(); } else if (inline is Run) { retVal = new Run(((Run)inline).Text); } if (inline.ReadLocalValue(Inline.BackgroundProperty) != DependencyProperty.UnsetValue) { retVal.Background = inline.Background; } if (inline.ReadLocalValue(Inline.ForegroundProperty) != DependencyProperty.UnsetValue) { retVal.Foreground = inline.Foreground; } if (inline.ReadLocalValue(Inline.FontFamilyProperty) != DependencyProperty.UnsetValue) { retVal.FontFamily = inline.FontFamily; } if (inline.ReadLocalValue(Inline.FontSizeProperty) != DependencyProperty.UnsetValue) { retVal.FontSize = inline.FontSize; } if (inline.ReadLocalValue(Inline.FontStretchProperty) != DependencyProperty.UnsetValue) { retVal.FontStretch = inline.FontStretch; } if (inline.ReadLocalValue(Inline.FontStyleProperty) != DependencyProperty.UnsetValue) { retVal.FontStyle = inline.FontStyle; } if (inline.ReadLocalValue(Inline.FontWeightProperty) != DependencyProperty.UnsetValue) { retVal.FontWeight = inline.FontWeight; } if (inline.ReadLocalValue(Inline.TextEffectsProperty) != DependencyProperty.UnsetValue) { retVal.TextEffects = inline.TextEffects; } if (inline.ReadLocalValue(Inline.TextDecorationsProperty) != DependencyProperty.UnsetValue) { retVal.TextDecorations = inline.TextDecorations; } return(retVal); }
private static void SetDesignItemTextpropertiesFromInline(DesignItem targetDesignItem, Inline inline) { if (inline.ReadLocalValue(TextElement.BackgroundProperty) != DependencyProperty.UnsetValue) { targetDesignItem.Properties.GetProperty(TextElement.BackgroundProperty).SetValue(inline.Background); } if (inline.ReadLocalValue(TextElement.ForegroundProperty) != DependencyProperty.UnsetValue) { targetDesignItem.Properties.GetProperty(TextElement.ForegroundProperty).SetValue(inline.Foreground); } if (inline.ReadLocalValue(TextElement.FontFamilyProperty) != DependencyProperty.UnsetValue) { targetDesignItem.Properties.GetProperty(TextElement.FontFamilyProperty).SetValue(inline.FontFamily); } if (inline.ReadLocalValue(TextElement.FontSizeProperty) != DependencyProperty.UnsetValue) { targetDesignItem.Properties.GetProperty(TextElement.FontSizeProperty).SetValue(inline.FontSize); } if (inline.ReadLocalValue(TextElement.FontStretchProperty) != DependencyProperty.UnsetValue) { targetDesignItem.Properties.GetProperty(TextElement.FontStretchProperty).SetValue(inline.FontStretch); } if (inline.ReadLocalValue(TextElement.FontStyleProperty) != DependencyProperty.UnsetValue) { targetDesignItem.Properties.GetProperty(TextElement.FontStyleProperty).SetValue(inline.FontStyle); } if (inline.ReadLocalValue(TextElement.FontWeightProperty) != DependencyProperty.UnsetValue) { targetDesignItem.Properties.GetProperty(TextElement.FontWeightProperty).SetValue(inline.FontWeight); } if (inline.TextDecorations.Count > 0) { targetDesignItem.Properties.GetProperty("TextDecorations").SetValue(new TextDecorationCollection()); var tdColl = targetDesignItem.Properties.GetProperty("TextDecorations"); foreach (var td in inline.TextDecorations) { var newTd = targetDesignItem.Services.Component.RegisterComponentForDesigner(new TextDecoration()); if (inline.ReadLocalValue(TextDecoration.LocationProperty) != DependencyProperty.UnsetValue) { newTd.Properties.GetProperty(TextDecoration.LocationProperty).SetValue(td.Location); } if (inline.ReadLocalValue(TextDecoration.PenProperty) != DependencyProperty.UnsetValue) { newTd.Properties.GetProperty(TextDecoration.PenProperty).SetValue(td.Pen); } tdColl.CollectionElements.Add(newTd); } } }
static public void CheckTextBlockInherited(Inline i) { Assert.AreEqual("Portable User Interface", i.FontFamily.Source, "FontFamily"); Assert.AreEqual(11, i.FontSize, "FontSize"); Assert.AreEqual(DependencyProperty.UnsetValue, i.ReadLocalValue(Inline.FontSizeProperty), "FontSize local value"); Assert.AreEqual(FontStretches.Normal, i.FontStretch, "FontStretch"); Assert.AreEqual(FontStyles.Normal, i.FontStyle, "FontStyle"); Assert.AreEqual(FontWeights.Normal, i.FontWeight, "FontWeight"); Assert.IsNotNull(i.Foreground, "Foreground"); Assert.AreEqual(Colors.Black, (i.Foreground as SolidColorBrush).Color, "Foreground.Color"); Assert.AreEqual("en-us", i.Language.IetfLanguageTag, "Language"); Assert.IsNull(i.TextDecorations, "TextDecorations"); }
private DesignItem InlineToDesignItem(Inline inline) { DesignItem d = d = designItem.Services.Component.RegisterComponentForDesigner(CloneInline(inline)); if (inline is Run) { var run = inline as Run; if (run.ReadLocalValue(Run.TextProperty) != DependencyProperty.UnsetValue) { d.Properties.GetProperty(Run.TextProperty).SetValue(run.Text); } } else if (inline is Span) { } else if (inline is LineBreak) { } else { return(null); } if (inline.ReadLocalValue(TextElement.BackgroundProperty) != DependencyProperty.UnsetValue) { d.Properties.GetProperty(TextElement.BackgroundProperty).SetValue(inline.Background); } if (inline.ReadLocalValue(TextElement.ForegroundProperty) != DependencyProperty.UnsetValue) { d.Properties.GetProperty(TextElement.ForegroundProperty).SetValue(inline.Foreground); } if (inline.ReadLocalValue(TextElement.FontFamilyProperty) != DependencyProperty.UnsetValue) { d.Properties.GetProperty(TextElement.FontFamilyProperty).SetValue(inline.FontFamily); } if (inline.ReadLocalValue(TextElement.FontSizeProperty) != DependencyProperty.UnsetValue) { d.Properties.GetProperty(TextElement.FontSizeProperty).SetValue(inline.FontSize); } if (inline.ReadLocalValue(TextElement.FontStretchProperty) != DependencyProperty.UnsetValue) { d.Properties.GetProperty(TextElement.FontStretchProperty).SetValue(inline.FontStretch); } if (inline.ReadLocalValue(TextElement.FontStyleProperty) != DependencyProperty.UnsetValue) { d.Properties.GetProperty(TextElement.FontStyleProperty).SetValue(inline.FontStyle); } if (inline.ReadLocalValue(TextElement.FontWeightProperty) != DependencyProperty.UnsetValue) { d.Properties.GetProperty(TextElement.FontWeightProperty).SetValue(inline.FontWeight); } if (inline.TextDecorations.Count > 0) { d.Properties.GetProperty("TextDecorations").SetValue(new TextDecorationCollection()); var tdColl = d.Properties.GetProperty("TextDecorations"); foreach (var td in inline.TextDecorations) { var newTd = designItem.Services.Component.RegisterComponentForDesigner(new TextDecoration()); if (inline.ReadLocalValue(TextDecoration.LocationProperty) != DependencyProperty.UnsetValue) { newTd.Properties.GetProperty(TextDecoration.LocationProperty).SetValue(td.Location); } if (inline.ReadLocalValue(TextDecoration.PenProperty) != DependencyProperty.UnsetValue) { newTd.Properties.GetProperty(TextDecoration.PenProperty).SetValue(td.Pen); } tdColl.CollectionElements.Add(newTd); } } return(d); }