0

I am reasonably proficient in XAML and WPF having trouble with binding to an additional control within an extended control from outside the control. Sorry, that's a real mouthful so let me explain:

I have a control that I have extended from a ComboBox and applied the template and overridden the property metadata and all that stuff and re-templated it so it looks and works as I want it to. Now, I want to add a TextBox to provide search functionality for the ComboBox which I have exposed dependency properties to determine if it is visible or not and added this to the first row of the Grid above the ItemsControl and all works fine. I have added a dependency property called IsFiltered and applied a template binding to determine if the filter is visible and from outside my control I can set this value and it all works.

However, I have added a dependency property to the extended ComboBox (MyComboBox if you like) as a string property so that I can assign a filter text property from my view model that will eventually work its way to the text box embedded within the control. The TextBox in the conrol is also bound using {TemplateBinding FilterText} dependency property, as it hooks back to my MyConboBox control and the assignment is accepted and recognised. However, while the property from my view model is set and read and interacts with the FilteText property in MyComboBox to which the TextBox inside by MyComboBox control template is also bound to, the TextBox does not trigger a change.

<TextBox
  Grid.Row="0"
  Margin="4"
  Text="{TemplateBinding FilterText}"
  BorderBrush="Red"
  Visibility="{TemplateBinding IsFiltered, Converter={converters:BoolToVisibilityConverter}}"/>

Can anyone help?

  • Couldn't you have just said something like "I have a TextBox in a UserControl and it's not updating when changed?" lol, that was a mouthful... Anyway, sounds like (if I'm interpreting that wall of text correctly) sounds like just missing `UpdateSourceTrigger=PropertyChanged` on the binding base for `Text` property. :) – Chris W. Sep 08 '16 at 15:23
  • it is probably `TemplateBinding` issue: TemplateBinding is one-way. fix: Binding with RelativeSource http://stackoverflow.com/questions/5913176/in-wpf-why-doesnt-templatebinding-work-where-binding-does – ASh Sep 08 '16 at 17:33
  • Why template binding in the first place? Styles yes, but data, I am not seeing the attraction. – ΩmegaMan Sep 08 '16 at 18:36
  • Thanks for the replies but the issue is slightly different because the TextBox is not in a user control. It is in an existing Wpf control (ComboBox) where I have created the following : public class MyControl : ComboBox and then overridden the entire template using DefaultStyleKeyProperty.OverrideMetadata(typeof(ItecComboBox), new FrameworkPropertyMetadata(typeof(ItecComboBox))); in a static constructor and then added a dependency property and set UpdateSourceTrigger and mode. I have done that but I have added a TextBox to the actual control template for my new combo box and cannot bin to dp – user6590430 Sep 09 '16 at 06:19
  • I have just found the issue and solved it, although I appreciate that my question was probably not clear enough,. In my Control template I needed to do this : Text="{Binding FilterText, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" instead of this : Text="{TemplateBinding FilterText}" and now it works. Thank you all for your help nevertheless. – user6590430 Sep 09 '16 at 07:39

0 Answers0