I am facing a problem with UpdateSourceTrigger property. I have a UserControl named LabelWithTextBox, where UpdateSourceTrigger (On Text Property) is not defined (therefore has default value). This should stay like this because of performance (Text should update when Focus is out of the TextBox).
But now I have a case where the UserControl should be used and the update should happen as the user types, therefore I want to set UpdateSourceTrigger to PropertyChanged.
Ideally the best solution would be if the UpdateSourceTrigger property could be inherited. The user uses in his View the UserControl and defines UpdateSourceTrigger = PropertyChanged, this information is handed over to my UserControl and everything works as expected. Does anyone know how I can archive this ?
What other options do I have ? How can I change the UpdateSourceTrigger Property at runtime ?
Here is the relevant UserControl (Code Behind) Code:
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text",
typeof(string),
typeof(LabelWithTextBox),
new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public string Text
{
get { return (string)this.GetValue(TextProperty); }
set { this.SetValue(TextProperty, value); }
}
And here is the UserControl (Xaml) Code:
<Grid Grid.Column="1">
<telerik:RadWatermarkTextBox TextChanged="TextBoxBase_OnTextChanged"
Name="TextBox"
Text="{Binding Text, Mode=TwoWay, ElementName=userControl}"
WatermarkContent="{Binding Placeholder, Mode=TwoWay, ElementName=userControl}"
TextWrapping="{Binding TextWrap, Mode=TwoWay, ElementName=userControl}"
AcceptsReturn="{Binding AcceptsReturn, Mode=TwoWay, ElementName=userControl}"
VerticalScrollBarVisibility="{Binding VerticalScrollBarVisibility, Mode=TwoWay, ElementName=userControl}"
MinLines="{Binding MinLines, Mode=TwoWay, ElementName=userControl}"
MaxLines="{Binding MaxLines, Mode=TwoWay, ElementName=userControl}"
IsReadOnly="{Binding IsReadOnly, ElementName=userControl}"/>
....
If add UpdateSourceTrigger = PropertyChanged to Text everything will work as expected. But I do not want that.
Here is for example how someone could use the UserControl in his View. What I am looking for is a way to hand over the value of the UpdateSourceTrigger to my UserControl, but how ?
<controls:LabelWithTextBox
Grid.Row="1"
Margin="0,5,0,0"
Label="Excel Blattname:"
SharedSizeGroup="LabelsX"
Text="{Binding SheetName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
DependencyProperty
for that in your control, then use the value in code behind to set theTextBox
. Just bear in mind that theDependencyProperty
when using Binding doesn't trigger the backing CLR property. – AffectingText
aDependencyProperty
in your user control? If it is "source", then it can be a usual property. What do you want to achieve? – ConcertgoerSetBinding(RadWatermarkTextBox.TextProperty, TextBinding)
. – BusterLostFocus
ofRadWatermarkTextBox
– Concertgoer