Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HotReload doesn't work for DataTemplate property changes in custom controls #10066

Closed
the8thC opened this issue Sep 12, 2022 · 15 comments
Closed
Labels
area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging partner/hot-reload-xaml Issues impacting XAML Hot Reload experiences platform/android 🤖 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@the8thC
Copy link

the8thC commented Sep 12, 2022

Description

Hello! I've made a simple custom control that has a DataTemplate property. When the template is loaded (Grid, for example), I assign an event handler for PropertyChanged. I also assign the same handler to the Grid in DataTemplate used in ListView.

If I change a DataTemplate property in XAML for my control nothing happens, but for ListView -- the PropertyChanged event is fired. Also, for the custom control event is fired when the property is changed in code behind.

I've attached a video and a link to reproduction project repository.

mAicbdAAwY.mp4

P.S. I'm one of the DevExpress .NET MAUI controls developers, this issue has a normal priority for us and we do not have a workaround. Thank you for your help.

Steps to Reproduce

  1. Clone reproduction project repo
  2. Build and run
  3. While running, in XAML, try to change BackgroundColor property of the Grid in the DataTemplate in the custom control.

Link to public reproduction project repository

https://github.com/the8thC/CustomControlHotReload

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android 12

Did you find any workaround?

No response

Relevant log output

No response

@the8thC the8thC added the t/bug Something isn't working label Sep 12, 2022
@jsuarezruiz jsuarezruiz added the area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging label Sep 12, 2022
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Sep 12, 2022
@ghost
Copy link

ghost commented Sep 12, 2022

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.

@drasticactions
Copy link
Contributor

@the8thC This issue is caused by ListView not being supported for MAUI Xaml Hot Reload. There is already an issue for that (#9640) and I am working on figuring out how to make it work. If you can replicate your issue outside of ListView, please post a repo and I'm more than happy to look at it.

@drasticactions
Copy link
Contributor

drasticactions commented Sep 13, 2022

I reread the issue. Sorry for that, I should have been more careful. Unless you have a custom ListView control then I don't know how that works for you, because it shouldn't.

In terms of the custom controls, that issue should be fixed with #8947. TL;DR is MAUI was sending the wrong source info for nested controls, linking to the original XAML page rather than its implementation. That meant you could only implement changes inside of the original control XAML page. My change fixed that, and testing your repo it works fine.

I would test this against MAUI Main, or until whenever the next service release is that includes this PR.

@drasticactions drasticactions added the s/needs-info Issue needs more info from the author label Sep 13, 2022
@ghost
Copy link

ghost commented Sep 13, 2022

Hi @the8thC. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@enisn
Copy link

enisn commented Sep 13, 2022

How did you implement ItemTemplate in your control?

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Sep 13, 2022
@the8thC
Copy link
Author

the8thC commented Sep 13, 2022

How did you implement ItemTemplate in your control?

https://github.com/the8thC/CustomControlHotReload
You can see here in this repo (which is in the 1st comment)

@the8thC
Copy link
Author

the8thC commented Sep 22, 2022

@drasticactions I can still reproduce this on 6.0.540

JUs989vUto.mp4

@drasticactions
Copy link
Contributor

Did you try MAUI main?

In the Live Visual Tree for the control, if you click on the XAML Source Icon for a given item, does it go to the MainPage.xaml, or to the original controls XAML? If it goes to that, then it didn't work. If it does, then that's my fix, and you're having another bug.

@the8thC
Copy link
Author

the8thC commented Sep 26, 2022

It goes to the original controls XAML. So that means it's some other bug?

explorer_B5bsHVO7u5.mp4

@the8thC
Copy link
Author

the8thC commented Dec 9, 2022

@drasticactions any updates on this?

@jonathanpeppers jonathanpeppers added the partner/hot-reload-xaml Issues impacting XAML Hot Reload experiences label Jan 24, 2023
@taublast
Copy link
Contributor

taublast commented Feb 1, 2023

The main step here would be to issue a doc on how to write custom controls compatible with hotrealod. Need guidelines for developers along with public methods to trigger hot reload.

"This issue is caused by ListView not being supported for MAUI Xaml Hot Reload" - who could fix that besides thoses carrying the knoweldge about hotrelad internals.

@taublast
Copy link
Contributor

Still forced to cut datatemplate, apply hotreload, undo, apply hotreload, to make changes to datatemplate content reflect inside custom control. Sound nice huh. :)
How come hotreload issue was put to backlog? Hotreload is one of the not many maui strengths.

@Zhanglirong-Winnie Zhanglirong-Winnie added s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage labels May 26, 2023
@Zhanglirong-Winnie
Copy link
Collaborator

Verified this issue with Visual Studio 17.7.0 Preview 1.0. Can repro on android platform with above project.
CustomControlHotReload-master.zip
Android

@drasticactions
Copy link
Contributor

@taublast @the8thC

image

The answer for this is IVisualTreeElement. The inner template is missing from the Visual Children list, so it will never be able to be hot reloaded.

public class MyTemplatedControl : VisualElement, IVisualTreeElement
{
    public static readonly BindableProperty ItemTemplateProperty =
        BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(MyTemplatedControl), null, propertyChanged: OnItemTemplateChanged);

    public DataTemplate ItemTemplate {
        get { return (DataTemplate)GetValue(ItemTemplateProperty); }
        set { SetValue(ItemTemplateProperty, value); }
    }

    public VisualElement Item { get; set; }

    static void OnItemTemplateChanged(BindableObject bindable, object oldValue, object newValue) {
        Console.WriteLine($"ItemTemplate changed from {oldValue} to {newValue}!");
    }

    IReadOnlyList<IVisualTreeElement> IVisualTreeElement.GetVisualChildren()
    {
       return new List<IVisualTreeElement>() { Item };
    }
}

Switch your MyTemplatedControl to this,

image

And the datatemplate shows up in LVT, and can now be edited.

@drasticactions
Copy link
Contributor

This is a duplicate of #10390. I am working on documenting IVisualTreeElement to help expose these functions for use cases like this, and this is a great example of where not implementing it can cause problems. It may be worth thinking of better ways to expose children for DataTemplate elements at a generic MAUI level too so you wouldn't have to implement this (@PureWeen).

I am going to close this issue. If there are other use cases you're hitting then try implementing IVisualTreeElement, and if that doesn't work then file a new bug.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging partner/hot-reload-xaml Issues impacting XAML Hot Reload experiences platform/android 🤖 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants