I have a custom control called EnhancedTextBox
which is a UserControl that has a TextBox
and a Button
. To the consumer I want it to mostly look like a TextBox, so I did the following:
<UserControl.Template>
<ControlTemplate TargetType="textBoxes:EnhancedTextBox">
...
<TextBox Text="{TemplateBinding Text}"...
And in EnhancedTextBox I have
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof (String), typeof (EnhancedTextBox));
public String Text
{
get { return (String) GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
Yet, when I use it as the following:
<EnhancedTextBox Text="{Binding MyText, Mode=TwoWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}}" />
Then, MyText
is never updated, as well as I inspect EnhancedTextBox.Text
and it is null. What am I missing? I have been staring at this for a bit and can't figure out what is wrong. I even thought it might be the fact that I was using the same name, so create a property called Text1
which did not work....
Also of note, if I use a regular TextBox
, then this all works. So, I am fairly certain the problem is with the EnhancedTextBox
itself
<EnhancedTextBox Text={Binding MyText, Mode=TwoWay} />
? – StempsonTextBox
defaults to 2way binding anyway – PolakTextProperty
actually needed? Can you not just have a regular property that the text box is bound to? – Yunyunfei