// Helper to set property value on element. private static void SetPropertyValue(TextElement element, DependencyProperty property, object currentValue, object newValue) { if (!TextSchema.ValuesAreEqual(newValue, currentValue)) { // first clear and see if it will do element.ClearValue(property); // if still need it, set it if (!TextSchema.ValuesAreEqual(newValue, element.GetValue(property))) { element.SetValue(property, newValue); } } }