question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Binding to the text property with UpdateSourceTrigger=PropertyChanged doesn't work

See original GitHub issue

So one solution would be to change the xaml to

<TextBox x:Name="PART_Editor"
                                             HorizontalAlignment="Stretch"
                                             VerticalAlignment="Center"
                                             Style="{StaticResource ResourceKey=TransparentTextBoxStyle}"
                                             Text="{Binding Path=Text, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

This would have a very minor performance hit, however clearly no one is relying on this property currently. I would like if it could somehow automatically use the right one or be a user preference. I think we could do the user preference by adding another parameter on the AutoCompleteTextBox of “UpdateTextExplicitly” and then manually establish the binding in code behind rather than in xaml.

I figured open an issue for discussion.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
quicolicommented, Nov 26, 2017

Go on with option 2, so user can choice what is better… Agree?

On Nov 26, 2017 19:23, “Mitch Capper” notifications@github.com wrote:

I wish:) As far as I know we cannot have the binding mirror the parent. Some googling has others with custom user controls having the same issue. I see we have 3 options:

  1. Change the xaml we have to always do propertychanged, a minor performance hit occurs all we are doing is updated the backend value however so performance hit should be extremely negligible ( https://stackoverflow.com/questions/6532383/textbox- updatesourcetrigger-propertychanged-does-it- really-affect-performanc?rq=1 https://stackoverflow.com/questions/6532383/textbox-updatesourcetrigger-propertychanged-does-it-really-affect-performanc?rq=1 ). As long as the user doesn’t change their code to also update on PropertyChanged their code will not have the binding called any more often.
  2. We add another property to the control like UpdateTextOnPropertyChanged and then bind the xaml to the class in code behind, this way the user has full control on if we are binding in
  3. We do nothing, people already use the control without issue and I can use some View hacking to get around the problem for myself.

Personally I think performance wise it would be fairly minor to do item 1 but let me know the preferred call and I can do a PR.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/quicoli/WPF-AutoComplete-TextBox/issues/9#issuecomment-347031670, or mute the thread https://github.com/notifications/unsubscribe-auth/AH_-j7UQv4RlEvpnW2RKAQ4v0zFlpvL4ks5s6bqkgaJpZM4QqLtx .

0reactions
matosjrcommented, Apr 16, 2020

I wish:) As far as I know we cannot have the binding mirror the parent. Some googling has others with custom user controls having the same issue. I see we have 3 options:

  1. Change the xaml we have to always do propertychanged, a minor performance hit occurs all we are doing is updated the backend value however so performance hit should be extremely negligible (https://stackoverflow.com/questions/6532383/textbox-updatesourcetrigger-propertychanged-does-it-really-affect-performanc?rq=1). As long as the user doesn’t change their code to also update on PropertyChanged their code will not have the binding called any more often.
  2. We add another property to the control like UpdateTextOnPropertyChanged and then bind the xaml to the class in code behind, this way the user has full control on if we are binding in
  3. We do nothing, people already use the control without issue and I can use some View hacking to get around the problem for myself.

Personally I think performance wise it would be fairly minor to do item 1 but let me know the preferred call and I can do a PR.

<TextBox x:Name="PART_Editor" HorizontalAlignment="Stretch" VerticalAlignment="Center" Style="{StaticResource ResourceKey=TransparentTextBoxStyle}" Text="{Binding Path=Text, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

I suspect the problem is that Text="{Binding Path=Text, ... is trying to bind TextBox.Text to a property in your ViewModel, instead of the AutoCompleteTexBox.Text, it was the case for me in a different solution. It is worth to check. If not, another problem is that if inside AutoCompleteTexBox.cs you assign values direct to TextBox.Text by doing something like _tb.Text = "something", it won’t work. What I did was use this.Text = "something" instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UpdateSourceTrigger not working?
This example seems to work fine: Code: public partial class MainWindow : Window, INotifyPropertyChanged { public MainWindow() ...
Read more >
The UpdateSourceTrigger property
This behavior is controlled by a property on the binding called UpdateSourceTrigger. It defaults to the value "Default", which basically means that the...
Read more >
INotifyPropertyChanged doesnt work when updating data ...
The problem is that you have not specific current DataContext when used Binding , For solving this problem you could specific current ...
Read more >
“Propertychange” is not firing up when text is changed or ...
The issue is even when my ViewModel is implementing Inotification Changed interface and the property is bound tot the text property of the ......
Read more >
UpdateSourceTrigger=PropertyChanged Doesn't Work On ...
If you have an editor control (DoubleEditBox, Int32EditBox) that uses a DataBinding for it's value, with UpdateSourceTrigger=PropertyChanged ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found