In WPF, why doesn't TemplateBinding work where Binding does?

前端 未结 2 2051
轻奢々
轻奢々 2020-11-28 11:40

Ok... this is leaving me scratching my head. I have two WPF controls--one\'s a user control and the other\'s a custom control. Let\'s call them UserFoo and CustomFoo. In

2条回答
  •  孤街浪徒
    2020-11-28 12:17

    TemplateBinding does not support two-way binding, only Binding does that. Even with your BindsTwoWayBeDefault option, it won't support two-way binding.

    More info can be found here, but to summarize:

    However, a TemplateBinding can only transfer data in one direction: from the templated parent to the element with the TemplateBinding. If you need to transfer data in the opposite direction or both ways, a Binding with RelativeSource of TemplatedParent is your only option. For example, interaction with a TextBox or Slider within a template will only change a property on the templated parent if you use a two-way Binding.

提交回复
热议问题