dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.21k stars 1.74k forks source link

TemplateBinding of custom control dependency properties does not get applied when style is imported from App.xaml #10873

Open vova1987 opened 2 years ago

vova1987 commented 2 years ago

Using the standard .NET MAUI template in VS2022, version 17.3.6. .NET Core version is 6.0 Development environment is Window 10 64 bit.

Steps to reproduce:

  1. Create a Control class inheriting from TemplatedView (e.g. InputView). Add at least one dependency property (e.g. Text, Label).
  2. Inside Styles.xaml (resource dictionary imported in App.xaml, built into the project template), declare a new style with TargetType="local:InputView" where local is a namespace alias pointing to the root namespace.
  3. Inside the style, add a setter for the control template and create a basic layout (Grid, VerticalStackPanel).
  4. Make sure to apply templateBinding to bind dependency property values to the control template
  5. On the MainPage, add an instance of the custom control, and make sure to set the dependency properties (e.g. text, label)
  6. Run The project (does not matter on which platform)

Result: Template binding not applied and no binding errors appear. The control template does get applied, but custom dependency properties are NOT visible. Workround: Move the style to the MainPage resources section and re-run the project. The binding will now be applied and the custom dependency properties become visible. Another (strange) workaround is to apply some changes (any changes, e.g add another container around the main layout) to the style with hot-reload while debugging. This will refresh the view and the templateBinding will now work!

An example solution is attached.

TemplateBindingNotAppliedBug.zip

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

PureWeen commented 2 years ago

@StephaneDelcroix

Zhanglirong-Winnie commented 1 year ago

Verified this issue with Visual Studio Enterprise 17.8.0 Preview 1.0(.NET8). Can repro on android platform with sample project. TemplateBindingNotAppliedBug.zip