I am pretty sure I am doing something dreadfully wrong, but can't figure it out.
I created a simple wrapper around a class and added a dependency property so I could bind to it. However, the binding gives no errors, but does nothing.
In order to simplify things I changed the class to TextBox, and got the same results.
public class TextEditor : TextBox { #region Public Properties #region EditorText /// <summary> /// Gets or sets the text of the editor /// </summary> public string EditorText { get { return (string)GetValue(EditorTextProperty); } set { //if (ValidateEditorText(value) == false) return; if (EditorText != value) { SetValue(EditorTextProperty, value); base.Text = value; //if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("EditorText")); } } } public static readonly DependencyProperty EditorTextProperty = DependencyProperty.Register("EditorText", typeof(string), typeof(TextEditor)); #endregion #endregion #region Constructors public TextEditor() { //Attach to the text changed event //TextChanged += new EventHandler(TextEditor_TextChanged); } #endregion #region Event Handlers private void TextEditor_TextChanged(object sender, EventArgs e) { EditorText = base.Text; } #endregion } When I run the following XAML the first gives results, but the second one (EditorText) doesn't even hit the EditorText property.
<local:TextEditor IsReadOnly="True" Text="{Binding Path=RuleValue, Mode=TwoWay}" WordWrap="True" /> <local:TextEditor IsReadOnly="True" EditorText="{Binding Path=RuleValue, Mode=TwoWay}" WordWrap="True" />