AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.12k stars 2.26k forks source link

TemplateBinding is not updating value on control in TextBox.Inner***Content #11912

Open timunie opened 1 year ago

timunie commented 1 year ago

Discussed in https://github.com/AvaloniaUI/Avalonia/discussions/11891

Originally posted by **sn4k3** June 25, 2023 I'm trying to extend the NumericUpDown control to add Left content to it TextBox. If I enter static text it will show, however any `TemplateBinding` sees no alterations. Extended NumericUpDown xaml code: ```xml ``` Relevant part: ```xml Text="{TemplateBinding Text}" ToolTip.Tip="Old value" AcceptsReturn="False" TextWrapping="NoWrap" /> ``` Results in `InnerLeftContent` never to update the `Text` with `Text="{TemplateBinding Text}" ` ![image](https://github.com/AvaloniaUI/Avalonia/assets/113281/c59ac24a-b116-4fd7-b886-32de56f8080b) If I set fixed text, ie: `Text="123"` it will show ![image](https://github.com/AvaloniaUI/Avalonia/assets/113281/e16c38b3-0064-463c-87ac-cf9d464ad089) I believe I'm doing something wrong, but I can't figure out where's the problem Note: Attaching the debugger on `this.GetObservable(TextProperty).Subscribe` fires correctly, just to be sure that `Text` is getting the notification. **EDIT 1:** Found a workaround that works: `Text="{Binding $parent[controls:ResettableNumericUpDown].Text, Mode=OneWay}"` but it looks silly... Actually any binding inside only works with this way, TemplateBinding always null. Why?
cesarchefinho commented 1 year ago

Look material.avalonia, they have InnerLeft on textbox that works with binding

TomEdwardsEnscape commented 1 year ago

The TemplatedParent of the inner control (PART_OldValueTextBox) is not the outer NumericUpDown as expected, but PART_TextBox from within the template.

Looks like a control assigned to InnerLeftContent isn't assigned a templated parent when constructed from a XAML template.