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.27k stars 1.76k forks source link

[Enhancement] Hot Reload: improve x:Name API #622

Closed etvorun closed 1 year ago

etvorun commented 3 years ago

Consider following XAML

<Shell>
  <FlyoutItem x:Name="ItemsPageItem" Title='Browse'>
  <!-- <FlyoutItem x:Name="ItemsPageDetails" Title='Details'> -->
</Shell>

If user uncomments ItemsPageDetails item we need to create new FlyoutItem, add it to Shell and register ItemsPageDetails with appropriate namescope. VS Hot Reload attemps to find namescope by traversing ItemsPageDetails ancestors. However we currently fail to find namescope. The net result is new FlyoutItem appears in Live Visual Tree without a name. For more details see VS bug 1267625. One thing to note about names is that users will name elements not for the sake of referencing them via bindings and alike but just to be able to easily find right items in Live Visual Tree. Thus we would like to see following improvements:

  1. There should be public read-write VisualElement.Name property. Like it is in WPF and UWP.
  2. Better API for updating namescope registration. Which will deal with any MAUI internal optimizations and/or visual tree modificartions. Something like
namespace Xamarin.Forms.HotReload
{
  class HotReloadHelper
  {
      public void UpdateElementName(VisualElement element, string oldName, string newName) {};
  }
}
StephaneDelcroix commented 3 years ago

can't you use RegisterName()

etvorun commented 3 years ago

can't you use RegisterName()

We use, but it does not always work, e.g. see XET bug 1267625.

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.

spadapet commented 1 year ago

I just debugged this, and it seems like we (UITools MAUI TAP) aren't sending the TAP message UpdateNameRegistration when the x:Name is added or changed. When I forced a call to UpdateNameRegistration, then the new x:Name did show up in the Live Visual Tree.

So this could end up being a fix in MAUI TAP (UITools repo). I'll take this to debug more.

spadapet commented 1 year ago

@etvorun the fix went into UITools Xamarin hot reload code, not MAUI repo: